0

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.

L-Ray
  • 1,637
  • 1
  • 16
  • 29
WSDL
  • 35
  • 9
  • 1
    Have you checked i.e. via Firebug, if after clicking the Links in your browser the expected .xhtml/.jsf pages is requested/retrieved? I would guess, independent from what you click, the page requested by your browser is always the same. – L-Ray Dec 19 '13 at 13:50
  • i have used iframe in my tempalte. – WSDL Dec 20 '13 at 03:15
  • Well, the iFrame-Request should still be shown by FireBug after you request it/click the button. – L-Ray Dec 20 '13 at 07:59

1 Answers1

1

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...

Community
  • 1
  • 1
L-Ray
  • 1,637
  • 1
  • 16
  • 29
  • any solution to get the url back in filter? @L-Ray – WSDL Dec 20 '13 at 09:30
  • 1
    See the update. Give feedback if it works... and yes, upvotes appreciated. – L-Ray Dec 20 '13 at 13:33
  • view id is not showing full url.if the url to be shown would be http://localhost:8080/authenticationmodule/faces/xhtml/authentication/userUsageDetails.xhtml, getting only xhtml/authentication/userUsageDetails.xhtml any solution @L-Ray – WSDL Dec 23 '13 at 06:52