Flipkart Search

Monday, 5 January 2015

Useful methods in Oracle ADF part-2

//1. Method to call a flow in taskFlow programatically 


 public static void gotoFlow(String flowName) {
        FacesContext context = FacesContext.getCurrentInstance();
        Application app = context.getApplication();
        NavigationHandler handler = app.getNavigationHandler();
        handler.handleNavigation(context, null, flowName);
    }
//2. Util method to show error and Success Msg
 public static void showMsg(String msgBody, String msgSeverity) {
        FacesMessage fm = new FacesMessage(msgBody);
        if (msgSeverity.equals("info")) {
            fm.setSeverity(FacesMessage.SEVERITY_INFO);
        } else if (msgSeverity.equals("warn")) {
            fm.setSeverity(FacesMessage.SEVERITY_WARN);
        } else if (msgSeverity.equals("error")) {
            fm.setSeverity(FacesMessage.SEVERITY_ERROR);
        } else {
            fm.setSeverity(FacesMessage.SEVERITY_FATAL);
        }
        FacesContext fctx = FacesContext.getCurrentInstance();
        fctx.addMessage(null, fm);
    }
//3. Get Cookie value in ADF
 
        public static String getCookieValue(String cookieName) {
        FacesContext fctx = FacesContext.getCurrentInstance();
        ExternalContext ectx = fctx.getExternalContext();
        Map vRequestCookieMap = ectx.getRequestCookieMap();
        Cookie cookie = (Cookie)vRequestCookieMap.get(cookieName);
        if (cookie != null) {
            return cookie.getValue();
        }
        return null;
    }
   
   
//4. Load a jsp or jspx page (redirect to a page)
 
  public static String loadPage(String pageName) {
        FacesContext vFacesContext = FacesContext.getCurrentInstance();
        ExternalContext vExternalContext = vFacesContext.getExternalContext();
        ControllerContext controllerCtx = null;
        controllerCtx = ControllerContext.getInstance();
        String activityURL = controllerCtx.getGlobalViewActivityURL(pageName);
        try {
            vExternalContext.redirect(activityURL.substring(0,
                                                            activityURL.indexOf("?")));
        } catch (IOException e) {
            e.printStackTrace();

        }
        return null;
    }
//5. Initializing the ADFLogger

private static ADFLogger _logger = 
            ADFLogger.createADFLogger(YourClassName.class); 
//6. Clear the ADF table filter
    public static void removeFilter(RichTable tableBind,String processQueryName) {
        FilterableQueryDescriptor queryDescriptor =
            (FilterableQueryDescriptor)tableBind.getFilterModel();
        if (queryDescriptor != null &&
            queryDescriptor.getFilterCriteria() != null) {
            queryDescriptor.getFilterCriteria().clear();
//processQueryName can found in queryListner of table eg:- #{bindings.Employee1Query.processQuery}
            FacesUtils.invokeMethodExpression(processQueryName,
                                              Object.class, QueryEvent.class,
                                              new QueryEvent(tableBind,
                                                             queryDescriptor));
        }
    }
// 7.Implementing like type filter in ADF table filter
public static void likeFilter(RichTable tableBind,String processQueryName) {
        FilterableQueryDescriptor queryDescriptor =
            (FilterableQueryDescriptor)tableBind.getFilterModel();
        if (queryDescriptor != null &&
            queryDescriptor.getFilterCriteria() != null) {
            Map m=queryDescriptor.getFilterCriteria();
           
            Set keys = m.keySet();
           Map modified=new HashMap();
            for (Iterator i = keys.iterator(); i.hasNext();) {
                  String key = (String) i.next();
                  String value = (String) m.get(key);
                if(value!=null && !value.equals("")){
                    value="%"+value+"%";
                   
                }
                    modified.put(key,value);
                  System.out.println(key + " = " + value);
                }
            queryDescriptor.getFilterCriteria().clear();
            FacesUtils.invokeMethodExpression(processQueryName,
                                              Object.class, QueryEvent.class,
                                              new QueryEvent(tableBind,
                                                             queryDescriptor));
            queryDescriptor.setFilterCriteria(modified);
            FacesUtils.invokeMethodExpression(processQueryName,
                                              Object.class, QueryEvent.class,
                                              new QueryEvent(tableBind,
                                                             queryDescriptor));
        }
    }
// 8. Launching / Invoking a PopUp from Bean. [popupBind is binding of popup inside the bean]
RichPopup.PopupHints hints = new RichPopup.PopupHints();
                    popBind.show(hints);

No comments:

Post a Comment