Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
命令按钮上的JSF导航_Jsf - Fatal编程技术网

命令按钮上的JSF导航

命令按钮上的JSF导航,jsf,Jsf,我想有条件地导航到某个页面。如果某个条件为真,我希望导航到其他页面,否则我希望保持在同一页面上。我有点像:- <h:commandButton action="#{bean.navigate}"/> public String navigate(){ if(value <= 0) return "helloWorld"; else return ""; } 在bean.navigate中,我有如下内容:- <h:co

我想有条件地导航到某个页面。如果某个条件为真,我希望导航到其他页面,否则我希望保持在同一页面上。我有点像:-

<h:commandButton action="#{bean.navigate}"/>
public String navigate(){
    if(value <= 0)
        return "helloWorld";
    else
        return "";
}

在bean.navigate中,我有如下内容:-

<h:commandButton action="#{bean.navigate}"/>
public String navigate(){
    if(value <= 0)
        return "helloWorld";
    else
        return "";
}
公共字符串导航(){

如果(值您需要如下导航规则:

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

/firstpage.xhtml
地狱世界
/successPage.xhtml
/failPage.xhtml

如果您想停留在同一页面,需要返回
null

这些导航规则是必要的吗?我没有使用任何导航xml文件,仍然可以导航到不同的页面。我使用的是JSF 2.0