开发者

JSF navigation on commandbutton

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 act开发者_开发问答ion="#{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?


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


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜