How can I redirect in JSF 2.0

I want to redirect a link to a JSF page, how can I do this?

In HTML, I can use a tag <a>for this. But in JSF, I use <h:outputLink>or <h:commandLink>, since they can be conditionally displayed. I want to redirect the link to another page in the same application or to an external URL. How can I do this using JSF? How can I use actionin <h:commandLink>for this?

+5
source share
1 answer

Assuming you want to redirect to some.xhtmlwhich is placed in the website root folder:

  • You can just use plain HTML.

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

    <ui:fragment>.


  • <h:link> .

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

    : FacesServlet.


  • <h:commandLink> ?faces-redirect=true.

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

    : FacesServlet.


  • <h:outputLink>, .

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

URL : URL- JSF.

. :

+9

All Articles