“?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=...>为什么不到处使用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 执行页面到页面导航.您应该为此使用普通 <h:link><h:button> 而不是 <h:commandLink><h:commandButton>.

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.

如果您需要提交带有一些用户输入的表单,请使用 <h:commandLink> .但是,如果需要有条件地呈现/包含,结果往往只是呈现在同一页面中.只有在绝对需要转到不同页面(例如登录/注销)的成功提交时,您确实应该发送重定向.这就是所谓的 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天全站免登陆