I want to redirect from a link in a JSF page, how can I do it?
In HTML I can use <a> tag for this. But in JSF I use <h:outputLink> or <h:commandLink> as they can be conditionally rendered. I want redirect link to other page in same application or to an external URL. How can I do it with JSF? How can I use action in <h:commandLink> for this?
Assuming that you’d like to redirect to
some.xhtmlwhich is placed in web root folder:You can just continue using plain HTML.
For conditional rendering, just wrap it in an
<ui:fragment>.Or use
<h:link>with implicit navigation.Note: no need to prepend context path nor to include
FacesServletmapping.Or use
<h:commandLink>with?faces-redirect=true.Note: no need to prepend context path nor to include
FacesServletmapping.Or use
<h:outputLink>, but you need to specify context path.Redirecting to an external URL is already answered in this duplicate: Redirect to external URL in JSF.
See also: