【问题标题】:Explicit url redirect in JSF 2.0JSF 2.0 中的显式 url 重定向
【发布时间】:2012-10-30 23:35:51
【问题描述】:

我下面有以下两页。

hello.xhtml,由 .../hello.jsf url 渲染。

<h:form>
  <h:commandButton id="submit" value="Submit" action="response"/>
</h:form>

response.xhtml,由 .../response.jsf url 呈现。

<h:form>
  <h:commandButton id="back" value="Back" action="hello"/>
</h:form>

当点击提交按钮时,hello页面被重定向到响应页面,但url保持不变,即url仍然是.../hello.jsf。

单击提交按钮后,我希望网址为 .../response.jsf。请帮忙?

非常感谢!

【问题讨论】:

    标签: url jsf redirect


    【解决方案1】:

    redirect 属性添加到您的faces_config.xml 文件中,如下所示:

     <navigation-rule>
        <from-view-id>/hello.xhtml</from-view-id>
        <navigation-case>
            <from-outcome>response</from-outcome>
            <to-view-id>/response.xhtml</to-view-id>
           <!--the redirect element -->
            <redirect/>
        </navigation-case>
    </navigation-rule>
    

    编辑:我的印象是您在导航结果样式中使用了faces-config.xml。我个人已经确认,您正在做的事情对于新的 JSF 2 样式导航也是允许的。请参阅 BalusC 对在 JSF2 样式导航处理中使用 redirect url 参数的回答

    【讨论】:

      【解决方案2】:

      如果您实际上没有使用 kolossus 所暗示的老式 JSF 导航案例,而是使用新的 JSF2 隐式导航功能,那么只需将 faces-redirect=true 查询字符串参数添加到结果中。

      <h:form>
        <h:commandButton id="submit" value="Submit" action="response?faces-redirect=true" />
      </h:form>
      

      但是,如果您根本不需要调用任何 bean 操作,并且打算使用普通的页面到页面导航,那么为此执行 POST 请求是没有意义的.那就用&lt;h:button&gt;吧。

      <h:button id="submit" value="Submit" outcome="response" />
      

      另见:

      【讨论】:

      • 不知道在视图类型导航中不添加页面扩展可以逃脱。这就是为什么它在我看来像老式导航
      猜你喜欢
      • 2011-09-25
      • 2013-06-26
      • 2011-04-26
      • 1970-01-01
      • 1970-01-01
      • 2014-03-21
      • 2011-07-02
      • 2015-03-06
      相关资源
      最近更新 更多