【问题标题】:Navigation rule not firing导航规则未触发
【发布时间】:2012-09-22 21:06:41
【问题描述】:

我的导航规则如下所示:

<navigation-rule>
    <display-name>forgotPwd</display-name>
    <from-view-id>/login/forgotpwd.jsf</from-view-id>
    <navigation-case>
        <from-outcome>pass</from-outcome>
        <to-view-id>/login/pwdresetcomplete.xhtml</to-view-id>
    </navigation-case>
    <navigation-case>
        <from-outcome>fail</from-outcome>
        <to-view-id>/login/forgotpwd.xhtml</to-view-id>
    </navigation-case>
</navigation-rule>

所以我这样做是为了触发导航规则:

  • 导航到/login/forgotpwd.jsf?uuid=fed8b3f7-ed33-4941-8306-3d2afbb8d1d0

此页面具有以下形式:

<h:form id="resetForm">
<!-- Omitting the login fields --> 
    <h:commandButton type="submit" id="resetPassword" value="Save" styleClass="btn small" action="#{registration.resetPassword}" >
        <f:param name="uuid" value="#{facesContext.externalContext.requestParameterMap.uuid}" />
    </h:commandButton>
</h:form>

(将uuid作为查询字符串参数传入,会调用registration.resetPassword函数。)

这里是registration.resetPassword java代码:

(为简洁起见省略了细节)

public String resetPassword() {
  // If good
  return "pass";
  // If bad
  return "fail"
}

问题:当它返回“pass”时,导航规则没有触发。它回到 /login/forgotpwd.jsf 而不是 /login/pwdresetcomplete.jsf

这是因为它附加了 UUID 参数吗?为什么我的导航没有触发?

是否有一些我可以触发的 log4j 日志记录来查看为什么这不起作用?

【问题讨论】:

    标签: jsf navigation primefaces


    【解决方案1】:
    <from-view-id>/login/forgotpwd.jsf</from-view-id>
    

    from-view-id 必须是视图 ID,而不是虚拟 URL。因此,它不应包含.jsf 扩展名。

    <from-view-id>/login/forgotpwd.xhtml</from-view-id>
    

    顺便说一句,请求参数在#{param} 可用的视图中。与#{facesContext.externalContext.requestParameterMap} 相比,这节省了一些字符。

    <f:param name="uuid" value="#{param.uuid}" />
    

    另见implicit objects in EL。另一个顺便说一句,您使用的是哪个 JSF 版本并不完全清楚,但是自从 JSF 2.0(我猜您已经在使用 Facelets 时使用它)以来,您不再需要导航案例 XML 地狱了。您可以直接从操作方法返回(相对和/或无扩展名)to-view-id

    public String resetPassword() {
      // If good
      return "pwdresetcomplete";
      // If bad
      return "forgotpwd"
    }
    

    这样你就可以摆脱整个&lt;navigation-rule&gt;。另见implicit navigation

    【讨论】:

    • 我一直想知道他们是否已经弄清楚了。是的,我在 JSF 2.0 上。太棒了,谢谢!
    【解决方案2】:

    我添加了这两个规则......现在它可以工作了。不确定是哪一个做的,但使用 from-action 让它更快乐。

    <navigation-rule>
            <display-name>forgotPwd</display-name>
            <from-view-id>/login/forgotpwd.xhtml</from-view-id>
            <navigation-case>
                <from-action>#{registration.resetPassword}</from-action>
                <from-outcome>pass</from-outcome>
                <to-view-id>/login/pwdresetcomplete.xhtml</to-view-id>
            </navigation-case>
            <navigation-case>
                <from-action>#{registration.resetPassword}</from-action>
                <from-outcome>fail</from-outcome>
                <to-view-id>/login/forgotpwd.xhtml</to-view-id>
            </navigation-case>
        </navigation-rule>
        <navigation-rule>
            <display-name>forgotPwd</display-name>
            <from-view-id>/login/forgotpwd.jsf</from-view-id>
            <navigation-case>
                <from-action>#{registration.resetPassword}</from-action>
                <from-outcome>pass</from-outcome>
                <to-view-id>/login/pwdresetcomplete.xhtml</to-view-id>
            </navigation-case>
            <navigation-case>
                <from-action>#{registration.resetPassword}</from-action>
                <from-outcome>fail</from-outcome>
                <to-view-id>/login/forgotpwd.xhtml</to-view-id>
            </navigation-case>
        </navigation-rule>  
    

    【讨论】:

      猜你喜欢
      • 2014-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-14
      • 2012-07-07
      • 2019-11-20
      • 1970-01-01
      • 2015-02-03
      相关资源
      最近更新 更多