0

I config error page in web.xml as following:

 <error-page>
        <exception-type>java.lang.Throwable</exception-type>
        <location>/faces/error.xhtml</location>        
    </error-page>

In my index.xhtml have one input field:

 <h:form>
        <h:inputText value="#{errorBean.text}"  />
        <h:commandButton value="submit" action="index.xhtml"/>
    </h:form>

And my ManagedBean checked user input. If user don't type anything, bean will throw Exception as following:

@ManagedBean(name = "errorBean")
@SessionScoped
public class ErrorBean {

    private String text;
    private Exception e;

    /**
     * Creates a new instance of ErrorBean
     */
    public ErrorBean() {
    }

    public String getText() {
        return text;
    }

    public void setText(String text) throws Exception{
        if (text.equalsIgnoreCase("")) {

         throw new Exception();
        } else {
            this.text = text;
        }
    }   
}

My question is: why is exception throw, url in browser is :

 http://localhost:8888/ErrorNavigator/faces/index.xhtml,

I think it is:

http://localhost:8888/ErrorNavigator/faces/error.xhtml

How do I config to url in browser is:

http://localhost:8888/ErrorNavigator/faces/error.xhtml

Please help me!!!!

Vuka
  • 23
  • 4
  • possible duplicate of [Redirect to an error page in JSF](http://stackoverflow.com/questions/9259579/redirect-to-an-error-page-in-jsf) – Aritz Aug 01 '13 at 05:50
  • It seems not possible simply because you would lose the exception info in case of doing a redirection. Alternatively you can create your own error page (managed as a normal navigation case) and redirect to it in case of exception. That way you could keep the exception itself (using flash scope or similar) changing the url in the address bar. – Aritz Aug 01 '13 at 06:04
  • @XtremeBiker Could you give a simple example? I'm not really clear, thank you very much! – Vuka Aug 01 '13 at 10:22
  • However, forget about throwing exceptions in getter and setter methods. Exceptions should be thrown when loading the bean itself or before rendering the view, also in action methods. Getter/setters must remain for their single function, no logic code. [Have a look](http://stackoverflow.com/q/2090033/1199132). – Aritz Aug 01 '13 at 13:36

0 Answers0