2012-09-22 71 views
1

我有一个导航规则,看起来像这样:导航规则不点火

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

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

这是因为它有UUID参数附加到它吗?为什么我的导航不开火?

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

回答

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

这样你就可以摆脱整个<navigation-rule>。另见implicit navigation

+0

我一直在想,如果他们已经弄清楚了。是的,我使用JSF 2.0。真是太棒了,谢谢! –

+0

不客气。 – BalusC

0

我增加了这两个规则......现在它的工作。不知道哪一个做了它,但是使用从行动使它更加快乐。

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