FAQ: Why your JSF FacesError message might not be showing up in your JSP

By Alvin J. Alexander, devdaily.com

Using JavaServer Faces (JSF), if you can't see the error message you're creating in your controller/handler when you forward to a new JSP (JavaServer Page), the problem may be that you have a "redirect" tag in your faces-config.xml file.

For example, the following faces-config.xml example shows the problem, where I do have a redirect tag when I bounce control back to the login.jsp page:

<><navigation-rule>
 <from-view-id>/login.jsp</from-view-id>
    <navigation-case>
      <from-outcome>login-success</from-outcome>
      <to-view-id>/main.jsp</to-view-id>
      <redirect/>
    </navigation-case>

    <!-- the "redirect" tag below is bad; your error message (FacesError) will never be seen -->
    <navigation-case>
      <from-outcome>login-failure</from-outcome>
      <to-view-id>/login.jsp</to-view-id>
      <redirect/>
    </navigation-case>
</navigation-rule>

Fortunately this is a simple fix. To make sure users do see your error (FacesError) message, just take the redirect tag out of your navigation rule, as shown here:

<><navigation-rule>
  <from-view-id>/login.jsp</from-view-id>
  <navigation-case>
    <from-outcome>login-success</from-outcome>
    <to-view-id>/main.jsp</to-view-id>
    <redirect/>
  </navigation-case>

  <!-- taking the redirect tag out of here let's the user see your error message -->
  <navigation-case>
    <from-outcome>login-failure</from-outcome>
    <to-view-id>/login.jsp</to-view-id>
  </navigation-case>
</navigation-rule>

devdaily logo