JSF 2.2:找不到导航规则中的request-param

时间:2014-04-24 09:11:24

标签: jsf-2.2 faces-config

我有一个faces-config.xml,其中包含很多导航规则,但我无法在我的页面中获得重定向参数。

我对这个问题进行了很多搜索,但是找不到任何帮助。

detail.xhtml:

<p:commandLink action="#{bean.delete()}">
    <f:setPropertyActionListener target="#{bean.deletionSuccess}" value="true" />
    <p:confirm header="Confirmation" message="Are you sure?"
</p:commandLink>

faces-config.xml中:

<navigation-rule>
    <from-view-id>/myDetailPage.xhtml</from-view-id>
    <navigation-case>
        <from-outcome>deletionSuccess</from-outcome>
        <to-view-id>/myOverviewPage.xhtml</to-view-id>
        <redirect/>
    </navigation-case>
</navigation-rule>

Java的豆:

   private String deletionSuccess;

    public String delete() {
        // do something
        return "deletionSuccess";
    }
    public void setDeletionSuccess(String deletionSuccess) { this.deletionSuccess = deletionSuccess; }

    public String getDeletionSuccess() { return deletionSuccess; }

overview.xhtml:

<f:metadata>
    <f:viewParam name="deletionSuccess" value="#{bean.deletionSuccess}"/>
    <f:viewAction action="#{bean.init}"/>
</f:metadata>
...
<h:form id="mainform" class="form-horizontal overview" role="form" method="post">
    <h:panelGroup styleClass="row" rendered="#{!empty housePlantBean.deletionSuccess}">
...

我做错了什么?或者如何在我的XHTML页面中获取redirect-param?

非常感谢你的帮助!

1 个答案:

答案 0 :(得分:1)

这不会以这种方式运作。

首先,您需要在<f:viewParam> facelet上定义myOverviewPage.xhtml,例如:

<f:metadata>
    <f:viewParam name="deletionSuccess" value="#{bean.deletionSuccess}"/>
</f:metadata>

我想你已定义了它。


传递参数的简便方法是在<h:button> facelet上使用<h:link>myDetailPage.xhtml,例如:

<h:button outcome="deletionSuccess">
    <f:param name="deletionSuccess" value="#{true}"/>
</h:button>

但没有调用public String delete()方法。

因此,如果您想要重定向和调用此方法,则应使用<h:commandButton><h:commandLink>,例如:

<h:commandButton value="submit" action="#{bean.delete}">
    <f:setPropertyActionListener target="#{bean.deletionSuccess}" value="#{true}" />
</h:commandButton>

---更新
请在navigation-rule

中保留正确的文件名
<navigation-rule>
    <from-view-id>/detail.xhtml</from-view-id>
    <navigation-case>
        <from-outcome>deletionSuccess</from-outcome>
        <to-view-id>/overview.xhtml</to-view-id>
        <redirect include-view-params="true"/>
    </navigation-case>
</navigation-rule>

请添加到detail.xhtml

<p:confirmDialog global="true" showEffect="fade" >
   <p:commandButton value="Yes" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check"/>
   <p:commandButton value="No" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close"/>
</p:confirmDialog>

或删除 <p:confirm header="Confirmation" message="Are you sure?"/> 来自<p:commandLink>代码