Semantics of “?faces-redirect=true” in and why not use it everywhere

前端 未结 1 718
臣服心动
臣服心动 2020-12-06 12:30

I would like to understand what are the semantics behind appending the \"?faces-redirect=true\" in the action property of a t

相关标签:
1条回答
  • 2020-12-06 13:29

    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>.

    So instead of

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

    you should actually be using

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

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

    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.

    See also

    • 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?
    0 讨论(0)
提交回复
热议问题