Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get query parameters in ExceptionHandler?
    text
    copied!<p>In our project (<strong>JBoss 7.0.2</strong>, <strong>JSF 2</strong>), we work on a solution to catch all exceptions during user navigation and redirect them to nice error pages.</p> <p>I used an <code>ExceptionHandler</code>, inspired by a lot of <a href="http://ovaraksin.blogspot.com/2010/10/global-handling-of-all-unchecked.html" rel="nofollow">examples</a> and <a href="http://weblogs.java.net/blog/edburns/archive/2009/09/03/dealing-gracefully-viewexpiredexception-jsf2" rel="nofollow">tutorials</a> online.</p> <p>I managed to do a redirection feature without too much difficulty: in the <code>ExceptionHandler.handle()</code> method, for some exceptions (expired view/session, unauthenticated user asking a denied page, ...) I redirect the user on the login page through a good old</p> <pre><code>FacesContext.getCurrentInstance().getExternalContext().redirect(myRedirectPage); </code></pre> <p>with an additional query parameter containing the original url base64 encoded, and after a successful authentication I use the same redirection mechanism to send the user back to their page.</p> <hr> <p>The problem is with <code>ViewExpiredException</code> on JSF actions, by example when the user click after their view has expired on any button or link with action or actionListener, synchronous or ajax-style, like</p> <pre><code>&lt;h:commandButton action="#{myBean.myAction}" value="do that" /&gt; </code></pre> <p>or</p> <pre><code>&lt;h:commandLink value="do that too"&gt; &lt;f:ajax render=":aZone" execute="@form" listener="#{myBean.myOtherAction}" /&gt; &lt;/h:commandLink&gt; </code></pre> <p><strong>I cannot manage to obtain the query parameters in my <code>ExceptionHandler.handle()</code> method.</strong></p> <p>I tried to put my parameters in a <code>f:metadata</code> section, like</p> <pre><code>&lt;f:metadata&gt; &lt;f:viewParam name="myParam" value="#{myBean.myParam}" /&gt; &lt;/f:metadata&gt; </code></pre> <p>and to include them in the action, so in the method bound to button action I returned</p> <pre><code>"myPage.xhtml?includeViewParams=true" </code></pre> <p>but it changed nothing :-/</p> <p>Am I doing something wrong? Where am I supposed to find the query paremeters? Is it in</p> <pre><code>FacesContext.getCurrentInstance().getExternalContext().getRequest() </code></pre> <p>** UPDATE **</p> <p>As said in comments, view params are no more available after a <code>ViewExpiredException</code> (quite obvious, in fact), so params are to be stored elsewhere (@BalusC quickly suggested in a request scope or through cookie).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload