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

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

问题描述

我想了解在JSF2.0的<h:commandlink>标记的action属性中附加"?faces-redirect=true"后的语义.无论使用它还是不使用它,应用程序确实都导航到操作中指定的目标页面.因此,乍看之下,似乎唯一的效果是修饰,即向用户(如果他正在查看浏览器的访问URL)提供了已移至新页面的反馈.但是,如果它是如此无害且无副作用,那么我将不明白为什么它不是默认行为.我怀疑这与JSF2.0的基于后的机制有关.在浏览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".

meta-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> .但是,如果有条件地呈现/包含结果,则结果通常会在同一页面中显示,这比通常情况要多得多.仅在绝对需要转到其他页面(例如登录/注销)的成功提交时,您确实应该发送重定向.这就是所谓的后重定向获取模式.

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.

  • How to navigate in JSF? How to make URL reflect current page (and not previous one)
  • When should I use h:outputLink instead of h:commandLink?

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

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