How to handle session expiration and ViewExpiredException in JSF 2?

To handle the exception whenever the user invokes a synchronous POST request on a page while the HTTP session has been expired and the JSF view state saving method is set to server, add an <error-page> to the web.xml which catches the JSF ViewExpiredException and shows the home page. <error-page> <exception-type>javax.faces.application.ViewExpiredException</exception-type> <location>/home.xhtml</location> </error-page> To handle … Read more

Creating FacesMessage in action method outside JSF conversion/validation mechanism?

You can use FacesContext#addMessage() to add a FacesMessage to the context programmatically. FacesContext facesContext = FacesContext.getCurrentInstance(); FacesMessage facesMessage = new FacesMessage(“This is a message”); facesContext.addMessage(null, facesMessage); When you set the client ID argument with null, it will become a global message. You can display and filter them using <h:messages /> <h:messages globalOnly=”true” /> The globalOnly=”true” … Read more

How to get rid of WARNING: PWC4011: Unable to set request character encoding to UTF-8

JSF/Facelets uses by default UTF-8 to decode HTTP request parameters. GlassFish itself uses by default ISO-8859-1 do decode HTTP request parameters. HTTP request parameters can be parsed and decoded only once and this happens whenever a request parameter is requested by the code for the first time like so request.getParameter(“name”). So, if a request parameter … Read more

JSF implicit vs. explicit navigation

This is somewhat subjective, but ala, it boils down to the following: Navigation rules in XML are a maintenance hell. Using navigation rules suggests that the web application in question suffers from the “one URL behind” problem which causes bad user experience (pages are not bookmarkable). Using navigation rules suggests that the web application in … Read more

PrimeFaces validator not fired

According to the FileUpload and FileUploadRenderer source code, the validator is only invoked when mode=”simple” is been used (note: this in turn requires ajax=”false” on command). The advanced mode will namely not set the uploaded file as component’s submitted value, causing it to remain null until the listener method is invoked. As long as the … Read more