I need to show, or hide a search component in my JSF2 application based on the page the user is on. I’m trying to do this by setting a “fromPage” attribute into the session, for example like this:
session.setAttribute("fromPage", "aboutUs");
These attributes are being set whenever the user clicks on a link in the homepage, and I check for them while serving the site’s pages. It works well when I use h:commandLinks.
But when I change to h:link this stops working because apparently all the “outcome” methods of h:links on a page are getting called when the page is rendered, and so the “fromPage” attribute always represents the last “outcome” method called — and it’s useless for my purpose.
So, is there any other way to know which page is the user clicking to? And which page am I on?
Use
UIViewRoot#getViewId()to learn which view is currently been opened. The currentUIViewRootis available by the implicit EL variable#{view}.