2

I am trying to get page parameters to do some verification in a PhaseListener. To this date this solution was working, but got some error reports.

In a page file (.xhtml) I have this :

<ui:param name="userCase" value="229501"/>

And a PhaseListener, that runs AFTER any phase and get this parameter and do some security verifications and redirect to a error page:

FaceletContext faceletContext = (FaceletContext) FacesContext.getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY);
if (faceletContext != null) {
    String userCase = (String) faceletContext.getAttribute("userCase");
    // check permission
    if (!hasPermission(userCase)) {
        // redirect
        NavigationHandler nh = facesContext.getApplication().getNavigationHandler();
        nh.handleNavigation(facesContext, null, url);
        facesContext.renderResponse();
    }
}

The redirect don't work and got IllegalStateException.

Doing some research I've found this question:

JSF 2.0 Custom Exception Handler throws IllegalStateException on handleNavigation

And I succeed configuring this param.

<context-param>
    <param-name>javax.faces.FACELETS_BUFFER_SIZE</param-name>
    <param-value>65535</param-value><!-- 64KB --> 
</context-param>

So now I've identified that my problem is with already committed pages.

I've tried to check this BEFORE the phase, but now I can't get the param, since the FaceletContext is always null.

After this little context:

I need to configure a parameter in the pages, that I can recover and use before the page is committed to be able to redirect if the user can't access that page.

How can I achieve this?

Edit1:

I've tested with:

<c:set var = "userCase" value = "229501" scope = "request" />

But the same problem occurs, this variable is only available after the page is already committed.

Edit2:

I can't simply use the FACELETS_BUFFER_SIZE, since this application is quite large, and server memory is an issue.

0 Answers0