Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSF navigation on commandbutton

Tags:

jsf

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?

like image 735
TCM Avatar asked Mar 06 '26 23:03

TCM


2 Answers

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

like image 181
BalusC Avatar answered Mar 09 '26 16:03

BalusC


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>
like image 37
Roman Avatar answered Mar 09 '26 18:03

Roman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!