Question

I am using jsf2 and RichFaces. I want to track each page being browsed by the user.

For that I have created Servelet Filter which Intercepts the page being requested. In my project, I am using jsf template features where header and Footer are fixed. In the body part, I have defined menu.xhtml and an iframe tag. Response is targeted on to iframe whenever user clicks on any link on the menu.

My Problem is that, I am not getting the correct url of the page requested in the filter.

My Filter Snap

Below Shown is the Filter,looking For xhtml Page.

chain.doFilter(request, response);

HttpSession session = req.getSession(false);
if( null != session && (uri.contains(".xhtml") || null != session.getAttribute("userid"))){
    if(null != session.getAttribute("userid")){
        String userid = session.getAttribute("userid").toString();
        //for saving usage details 
        if(uri.contains(".xhtml")){                           
            System.out.println(".......Requeted Page.........."+req.getRequestURL().toString());
        saveUserUsage(req);
        }
    }
}

url getting in the filter is userdeskop.xhtml even though different links in the menu are selected.

Was it helpful?

Solution

Reason for the same url independent from the clicked menu might be the JSF Lifecycle:

  • it decides on server side on which page to deliver.

From that side, independent from what you click on e.g. a JSF Mojarra Implementation, the requested page might always be the same - just the parameters differ ... and the server does a redirect to the desired page (which is just too late for your filter to be recognized ;-) ).

Update: I would try to get a phase listener being executed before or after RENDER RESPONSE phase, because there the navigation goal should be resolved. Within the listener something like (untested example code)

public void afterPhase(PhaseEvent event)
{
  FacesContext context = event.getFacesContext();
  String viewId = context.getViewRoot().getViewId();
  ....
 }

might help you resolve the final url.

If you only want to resolve the urls for the main menu (I guess, that links are static and no managed bean method needs to be invoked), you can alternatively use h:outputLink, which resolves to fixed urls ( see When should I use h:outputLink instead of h:commandLink? for details) - this will work with your already existing listener.

Hope it helps...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top