wood burning stoves 2.0*
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 Murach's Java Servlets and JSP this week in the Servlets 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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: valueChangeListener and Exceptions
 
Similar Threads
Issue With selectOneMenu ValueChangeListener Not Firing
FacesMessages and valueChangeListener with immediate="true"
problem with <h:selectOneMenu > element and the submittion of its value
unexpected call to method or property access
selectOneMenu ValueChangeListener not Firing