“?faces-redirect=true"的语义在 <commandlink action=...>为什么不在任何地方使用它 [英] Semantics of "?faces-redirect=true" in <commandlink action=...> and why not use it everywhere

查看:18
本文介绍了“?faces-redirect=true"的语义在 <commandlink action=...>为什么不在任何地方使用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解在 标签的 action 属性中附加 "?faces-redirect=true" 背后的语义是什么在 JSF2.0 中.无论有没有它,应用程序确实导航到操作中指定的目标页面.所以乍一看似乎唯一的效果是装饰性的,即向用户提供反馈(如果他正在查看浏览器访问过的 URL)他已经移动到一个新页面.但如果它如此无害且无副作用,我不明白为什么它不是默认行为.我怀疑这与JSF2.0的基于post的机制有关.我注意到在浏览 JSF 应用程序时,人们在浏览器中看到的 URL(当未使用 ?faces-redirect=true 时)是上一个"页面"的 URL.

I would like to understand what are the semantics behind appending the "?faces-redirect=true" in the action property of a <h:commandlink> tag in JSF2.0. Whether with it or with out it, the application indeed navigates to the target page specified in the action. So at first glance it seems that the only effect is cosmetic, i.e. to provide feedback to the user (if he is looking at the browser's visited URL) that he has moved to a new page. But if it is so innocuous and side-effects-free I cannot see why it is not the default behaviour. I suspect that it has to do with the post-based mechanism of JSF2.0. I 've noticed when browsing through a JSF application that the URLs one sees at his browser (when ?faces-redirect=true is not used) are the ones of the "previous" "page".

元NB.我在防火墙后面并且受到SO 需要来自另一个域的外部 JavaScript"问题的困扰,所以我为没有格式化而道歉.当我可以从另一个域访问时,我还将在几个小时内提供有关您的答案的反馈.

meta-NB. I am behind a firewall and plagued with the "SO requires external JavaScript from another domain" issue so I apologize for the absence of formatting. I will also provide feedback on your answers in a few hours, when I can access from another domain.

推荐答案

根本不应使用 POST 执行页面到页面导航.你应该使用普通的 而不是 .

Page-to-page navigation should not be performed using POST at all. You should be using normal <h:link> or <h:button> for this instead of <h:commandLink> or <h:commandButton>.

所以代替

<h:commandLink value="Next page" action=nextpage.xhtml?faces-redirect=true" />

你应该实际使用

<h:link value="Next page" outcome="nextpage.xhtml" />

这有一个主要好处,即网站现在对 SEO 友好.Searchbots 即不索引表单.

This has the major benefit that the website is now SEO friendly. Searchbots namely doesn't index forms.

使用 如果您需要提交包含一些用户输入的表单.但是,如果需要有条件地呈现/包含,结果通常只会出现在同一页面中.只有在绝对需要转到不同页面(例如登录/注销)的成功提交时,您才确实应该发送重定向.这就是所谓的Post-Redirect-Get 模式.

Use the <h:commandLink> only if you need to submit a form with some user input. But more than often the result is just presented in the same page, if necesary conditionally rendered/included. Only on successful submits which absolutely needs to go to a different page (e.g. login/logout), you should indeed be sending a redirect. This is the so-called Post-Redirect-Get pattern.

这篇关于“?faces-redirect=true"的语义在 &lt;commandlink action=...&gt;为什么不在任何地方使用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆