Primefaces DialogFramework - How to show a dialog located in WEB-INF?

I am using Primefaces DialogFramework with

  • Primefaces 5.0
  • Mojarra 2.1.27
  • Glassfish 3.1.2.2 build 5

My problem is that if the user knows the location of my dialog, he can access it directly through the URL. I do not want this to be possible, so I thought that he could put the dialog in the WEB-INF folder of my web application, but now, if I want to open the dialog, I get a FileNotFound-Exception.

If my dialog is in some regular folder, it works fine

RequestContext.getCurrentInstance().openDialog("/myfolder/mydialog"); 
// this works as expected

but if it is in WEB-INF, it no longer works

RequestContext.getCurrentInstance().openDialog("/WEB-INF/mydialog",options,null);
// this is causing a fileNotFoundException

I also tried setting the navigation rule for this in faces-config, but again without success

<navigation-case>
    <from-outcome>mydialog</from-outcome>
    <to-view-id>/WEB-INF/mydialog.xhtml</to-view-id>
    <redirect />
</navigation-case>

, WEB-INF, ?

+4
1

, PrimeFaces Dialog Framework /WEB-INF . . POST, , JSF/PrimeFaces oncomplete script URL- (public!) JavaScript/jQuery, , , <iframe>, URL- URL- , , , . 2 , - URL- , - URL- <iframe>.

/WEB-INF, "" <p:dialog> JS/CSS. , <iframe>, . - referer, .

pfdlgcid ( Constants.DIALOG_FRAMEWORK.CONVERSATION_PARAM), . PrimeFaces, , , " " URL- . , /dialogs, . , HTTP 400 /dialogs/* pfdlgcid.

@WebFilter("/dialogs/*")
public class DialogFilter implements Filter {

    @Override
    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) res;
        String id = request.getParameter(Constants.DIALOG_FRAMEWORK.CONVERSATION_PARAM);

        if (id != null) {
            chain.doFilter(req, res); // Okay, just continue request.
        }
        else {
            response.sendError(HttpServletResponse.SC_BAD_REQUEST); // 400 error.
        }
    }

    // ...
}

pfdlgcid - . pfdlgcid . PrimeFaces DialogNavigationHandler, , , PrimeFaces . DialogNavigationHandler, pfdlgcid , , , .

DialogFilter:

public static Set<String> getIds(HttpServletRequest request) {
    HttpSession session = request.getSession();
    Set<String> ids = (Set<String>) session.getAttribute(getClass().getName());

    if (ids == null) {
        ids = new HashSet<>();
        session.setAttribute(getClass().getName(), ids);
    }

    return ids;
}

PrimeFaces DialogNavigationHandler 62:

DialogFilter.getIds((HttpServletRequest) context.getExternalContext().getRequest()).add(pfdlgcid);

<navigation-handler> faces-config.xml .

, if DialogFilter#doFilter() :

if (getIds(request).contains(id)) {
    // ...
}

. , URL <iframe> . , PrimeFaces, . pfdlgcid , - . , JS, .

, , , "" <p:dialog>.

+8

All Articles