2

我在下面有以下两页。

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。

单击提交按钮后,我希望 url 为.../response.jsf 。请问有什么帮助吗?

非常感谢!

4

2 回答 2

2

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

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

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

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

也可以看看:

于 2012-11-11T11:28:21.477 回答
2

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导航结果样式中的 a 。我已经亲自确认您正在做的事情对于新的 JSF 2 样式导航也是允许的。请参阅 BalusC 对redirect在 JSF2 样式导航处理中使用 url 参数的回答

于 2012-11-11T04:39:13.957 回答