Tracking previous page in JSF
I want to find out the previous page from where the current page is called. Based on the previous page I want to enable or disable a particular component. Can anybody h开发者_StackOverflow社区elp me in this regard.
Depends on the concrete functional requirement which isn't entirely clear from your question. You could pass an unique request parameter. E.g. when it concerns a GET link:
<h:link value="Next" outcome="next">
<f:param name="foo" value="bar" />
</h:link>
or a POST link:
<h:form>
<h:commandLink value="Next" action="next">
<f:param name="foo" value="bar" />
</h:commandLink>
</h:form>
with in next.xhtml
<h:someComponent rendered="#{param.foo == 'bar'}">
...
</h:someComponent>
or if you don't care about the param's value:
<h:someComponent rendered="#{not empty param.foo}">
...
</h:someComponent>
An alternative which can be much better if you don't want to allow the enduser being able to manipulate the request is to set a bean property during a POST action and then return to the next view:
<h:form>
<h:commandLink value="Next" action="#{bean.next}" />
</h:form>
with e.g.
public String next() {
foo = "bar";
return "next";
}
and in next.xhtml
<h:someComponent rendered="#{bean.foo == 'bar'}">
...
</h:someComponent>
精彩评论