• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ExceptionHandler does not work with the navigation rules of the faces-config.xml

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

in my welcome.xhtml page I have two forms `age-form and error-form`. The `error-form` is without navigation rules which works fine (I created it to find the error in the  age-form) and the other `age-form` is with 3 nagivation cases and it does not work. So when I enter age of zero, the `MyExceptionHandler-->Handler()` is being called but the iterator is empty and does not have a next item as in the screen shoot underneath. I want to invoke my error.xhtml page when I enter a value of `0` in `age-form` in the `welcome.xhtml` but I do not really know what else do I have to do to get it to work as in the error-form?

I appreciate any help.

Best
TheOcean

wlecom




faces-config.xml

 

MyExceptionHandlerFactory

 

MyExceptionHandler



screen shoot when calling the MyExceptionHandler by the error-form

Iterator is empty


screen shoot when calling the MyExceptionHandler by the age-form
Iterator is not empty
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Exceptions are not a good way to navigate JSF. Actually they're not a good way to navigate any webapp, but especially not JSF.

When a JSF method throws an Exception, it exits both JSF and the webapp itself and is caught by the container (the webapp server). If an exception page is defined, the container will construct and dispatch an internal URL request for that page.

JSF is not recommended for any page that is internally invoked by the container. Not only error pages, but login forms or any other page specified in web.xml. That's because the internal URL dispatcher may not invoke the FacesServlet - it's running along a different path than external requests do.

Actually, the "to" navigation element is new to me. Apparently it was added without much comment to JSF2. Most people use annotations and the JSF2 implicit navigation mechanism instead of using faces-config.xml for navigation.

In any event, if you find an error on a JSF page request, the first choice is generally to add it to the view error list and redisplay the page (using a null navigation target). This allows users to correct faulty inputs without having to re-enter all the fdata.

As a second option, where, for example, executing a page action results in a database error, you should define your own error view and navigate to it rather than throwing an Exception up to the server.  The JSF2 Flash scope can be handy when doing this.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic