2

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?

2 Answers 2

7

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

Sign up to request clarification or add additional context in comments.

Comments

3

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>

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.