How can I redirect in JSF 2.0

霸气de小男生 提交于 2019-11-29 00:10:25
BalusC

Assuming that you'd like to redirect to some.xhtml which is placed in web root folder:

  1. You can just continue using plain HTML.

    <a href="#{request.contextPath}/some.xhtml">go to some page</a>
    

    For conditional rendering, just wrap it in an <ui:fragment>.


  2. Or use <h:link> with implicit navigation.

    <h:link outcome="/some" value="go to some page" />
    

    Note: no need to prepend context path nor to include FacesServlet mapping.


  3. Or use <h:commandLink> with ?faces-redirect=true.

    <h:commandLink action="/some?faces-redirect=true" value="go to some page" />
    

    Note: no need to prepend context path nor to include FacesServlet mapping.


  4. Or use <h:outputLink>, but you need to specify context path.

    <h:outputLink value="#{request.contextPath}/some.xhtml" value="go to some page" />
    

Redirecting to an external URL is already answered in this duplicate: Redirect to external URL in JSF.

See also:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!