1 Reply Latest reply on Aug 15, 2006 12:19 AM by Jason Long

    getting referer

    nepoez nugget Newbie

      Is there a way to grab the referer in a backing bean? For statistics purpose.

        • 1. Re: getting referer
          Jason Long Master

          I use the following as a page action to log access to my application.

          In the @Create method I set the request. I am only interested in the "User-Agent" header, but I am sure you can get the referrer as well.

          @Stateful
          @Name("accessManager")
          @Scope(ScopeType.EVENT)
          public class AccessManagerBean implements Serializable, AccessManager {
          
          
           private static final long serialVersionUID = 2947953361734540770L;
          
           @EJB AccessDAO accessDAO;
           @EJB UsrDAO usrDAO;
          
          
           @Logger Log log;
          
           @SuppressWarnings("unused")
           @DataModel(scope = ScopeType.PAGE)
           private List<Access> accessList;
          
           @In(required = false)
           @Out(scope = ScopeType.PAGE, required = false)
           private Access accessNew;
          
           @In
           private FacesContext facesContext;
          
           @Factory("accessList")
           public void getList()
           {
           accessList = accessDAO.getAllAccesss();
           }
          
           @Factory("accessNew")
           public void getNew() {
           log.info("@Factory(roleNew)");
           accessNew = new Access();
           }
          
           private HttpServletRequest request;
          
           @Create
           public void setup() {
           request = (HttpServletRequest) facesContext.getExternalContext().getRequest();
           }
          
           public String select() {
           return null;
           }
          
           public String update() {
           clear();
           return null;
           }
          
           public String add() {
           Access access = new Access();
           access.setUsr(usrDAO.getUsrByJAAS(request.getRemoteUser()));
           access.setStartDate(new Date());
           access.setAddressIP(request.getRemoteAddr());
           access.setPath(request.getRequestURI());
           access.setUserAgent(request.getHeader("User-Agent"));
           access = accessDAO.makePersistent(access);
           return null;
           }
          
           private void clear(){ }
          
           public String delete()
           {
           return null;
           }
          
           @Destroy @Remove
           public void destroy() { }
          }