tags:

views:

279

answers:

2

Hello, I want to conditionally navigate to some page. If some condition is true i want to navigate to some other page else i want to remain on the same page. I have something like :-

<h:commandButton action="#{bean.navigate}"/>

in bean.navigate i have something like :-

public String navigate(){
    if(value <= 0)
        return "helloWorld";
    else
        return "";
}

But if i return "", error is thrown and in h:messages message is appended that page not found etc. How do i avoid this error?

+1  A: 

You need navigation rule like this:

<navigation-rule>
    <from-view-id>/firstpage.xhtml</from-view-id>
    <navigation-case>
        <from-outcome>helloWorld</from-outcome>
        <to-view-id>/successPage.xhtml</to-view-id>
    </navigation-case>
    <navigation-case>
        <to-view-id>/failPage.xhtml</to-view-id>
        <redirect/>
    </navigation-case>
</navigation-rule>
Roman
Are these navigation rules necessary? I haven't used any navigation xml file and still i am able to navigate to different pages. I am using JSF 2.0
Ankit Rathod
+2  A: 

You need to return null if you want to stay at the same page.

BalusC