JSF页面中的导航按钮

时间:2012-09-13 13:12:33

标签: java jsf jsf-2

我在faces-config.xml中有一个带导航规则的JSF按钮:

<h:commandButton id="newzone" styleClass="lbimage" value="New Zone" action="#{bean.navigateToNewZone()}">
    <f:ajax render="@form"></f:ajax>
</h:commandButton>

// Navigate to New Zone page
public int navigateToNewZone(){
    return 11472;
}

<navigation-rule>
    <description>Navigation rule to New Zone page</description>
    <from-view-id>/ZonesList.xhtml</from-view-id>
    <navigation-case>
        <from-action>#{ZonesController.navigateToNewZone()}</from-action>
        <from-outcome>11472</from-outcome>
        <to-view-id>/NewZone.xhtml</to-view-id>
    </navigation-case>
</navigation-rule>

我的问题是如何简化导航?我不想在faces-config.xml中创建导航规则。有没有办法从JSF按钮直接打开新页面?

2 个答案:

答案 0 :(得分:4)

  

有没有办法从JSF按钮直接打开新页面?

只需使用<h:button>代替<h:commandButton>。你根本不需要POST请求。

<h:button value="New Zone" outcome="/NewZone.xhtml" />

请注意,新的JSF 2.0“隐式导航”功能将隐式使用“from-outcome”作为“to-view-id”,因此您确实可以直接在{{使用“to-view-id” 1}}或其他答案暗示的返回值。

答案 1 :(得分:2)

您也可以直接使用action="/NewZone.xhtml",而无需在faces-config.xml内进一步配置。

相关问题