This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JSF and the fly likes valueChangeListener and Exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "valueChangeListener and Exceptions" Watch "valueChangeListener and Exceptions" New topic
Author

valueChangeListener and Exceptions

Robert Pond
Greenhorn

Joined: Sep 05, 2008
Posts: 3
I have a value change listener on a selectOneMenu that renders components based on what value is selected. I also have setup a basic error page to display for all Exceptions. This works correctly for all actions (that return strings to go to different views) but if there is an exception in the valueChangeListener, it is not directed to the error page. In the valueChangeListener I am calling context.renderResponse() like all the examples.

In my error log I can see that the Exception is generated with the stack trace etc.

If I doing something wrong, or is there a way to manually change the view to the error page?
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Throw the exception and/or don't call responsecomplete before the exception occurs.
Robert Pond
Greenhorn

Joined: Sep 05, 2008
Posts: 3
That already is not being called if the Exception occurs.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Ah yes, you're fully right. Uncaught exceptions which occur during phase events will be swallowed. Best is to catch the exception yourself and handle it accordingly, e.g. display facesmessage using FacesContext#addMessage() or to forward to error page using ExternalContext#dispatch().
Robert Pond
Greenhorn

Joined: Sep 05, 2008
Posts: 3
Thanks. I was able to get it to work using redirect but I had to specify the full address (with webapp name) to the jsp, not just the view id. Is there a way to do it otherwise. The ExternalContext dispatch() javadoc says that it must be accompanied by a call to ServletContext.forward.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: valueChangeListener and Exceptions