Get current/login URL using FacesContext

Posted: February 13, 2013 in web

On your abstract class or util

Getting your login page or home page

    protected String getLoginURL() {
        Object request = facesContext.getExternalContext().getRequest();
        if (request instanceof HttpServletRequest) {
            HttpServletRequest req = ((HttpServletRequest) request);
            String path = req.getRequestURL().toString().replace(req.getServletPath(), "");
            return path;
        }
        return null;
    }

Getting your full URL on the current page

    protected String getLoginURL() {
        Object request = facesContext.getExternalContext().getRequest();
        if (request instanceof HttpServletRequest) {
            HttpServletRequest req = ((HttpServletRequest) request);
            String path = req.getRequestURL().toString();
            return path;
        }
        return null;
    }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s