1HttpServletRequest req = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
2String url = req.getRequestURL().toString();
3return url.substring(0, url.length() - req.getRequestURI().length()) + req.getContextPath() + "/";
4// ...
5