【问题标题】:not forwarding or redirecting jsf不转发或重定向 jsf
【发布时间】:2012-06-07 19:23:04
【问题描述】:

我有两个页面可供注册。上一个我将用户数据放入请求范围的 bean 中,下一个我显示收集的数据。在第二页有一个按钮可以重定向用户登录。

这是 register.xhtml 的按钮操作。 regUser.register 的结果是 reg_success,这是我显示用户数据的第二页的名称。

        <p>
            <h:commandButton value="#{msgs.regButtonText}" action="#{regUser.register}"/>
        </p>

在 reg_success.xhtml 我有这个按钮的代码:

        <p>
            <h:commandButton value="#{msgs.regToLogin}" action="login"/>
        </p>

我的登录页面名为 login.xhtml。

即使我将此导航规则插入到我的 faces-config.xml 中,转发也不会发生。事实上,从 register.xhtml 用户被转发,并且第二页上的 url 没有改变。

<navigation-rule>
        <from-view-id>/reg_success.xhtml</from-view-id>
    <navigation-case>
        <from-outcome>login</from-outcome>
        <to-view-id>/login.xhtml</to-view-id>
        <redirect/>
    </navigation-case>
</navigation-rule>

【问题讨论】:

    标签: jsf navigation action


    【解决方案1】:

    &lt;h:commandButton&gt; 仅在 &lt;h:form&gt; 内时有效。另见commandButton/commandLink/ajax action/listener method not invoked or input value not updated的第一点。

    但在这种特殊情况下,您似乎不需要 POST 请求。只需使用&lt;h:button&gt; 即可。这会创建一个 GET 请求,而不需要 &lt;h:form&gt;

    <h:button value="#{msgs.regToLogin}" outcome="login" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-09
      • 2011-07-21
      • 2010-11-01
      • 2013-06-26
      相关资源
      最近更新 更多