Generate View URL in ADF

The following  getUrl method generates URL for you view in ADF application.
You pass servlet name and view id, I also overloaded getUrl method for making default servlet name as "faces".

   public static FacesContext getFacesContext() {  
     return FacesContext.getCurrentInstance();  
   public static ExternalContext getExternalContext() {  
     return getFacesContext().getExternalContext();  
   public static String getURL(String servletName, String viewId) {  
     HttpServletRequest request = (HttpServletRequest)getExternalContext().getRequest();  
     String requestUrl = request.getRequestURL().toString();  
     StringBuilder newUrl = new StringBuilder();  
     newUrl.append(requestUrl.substring(0, requestUrl.lastIndexOf(servletName)));  
     newUrl.append(viewId.startsWith("/") ? viewId : "/" + viewId);  
     return newUrl.toString();  
   public static String getURL(String viewId) {  
     return getURL("faces", viewId);  

Import the following Classes

 import javax.faces.context.ExternalContext;  
 import javax.faces.context.FacesContext;  
 import javax.servlet.http.HttpServletRequest;  


Popular posts from this blog

ADF : Get Current Logged User Name

OAF : Get Current Row in Table

ADF : Working with ViewCriteria