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);

Tuesday, 30 December 2014

Merge two Columns into one column while showing data Seperately

Use case scenario:  You may need to show your two column header as well as data into a single ADF Table column. 
Please refer the below image for use case:

ADF has made this use case very simple.
You have just wrap your existing(required) Columns into a single column and its done.

Here is the required code sample:
 <af:column headerText="Emplyee Name"  id="c5" align="center">
          <af:column headerText="First Name" id="c8">
                     <af:outputText value="F_Name #{vs.index+1} " id="ot6"/>
          </af:column>
          <af:column headerText="Last Name" id="c9">
                    <af:outputText value="L_Name #{vs.index+1}" id="ot5"/>
          </af:column>
 </af:column>

Implement selectBooleanRadio in Table Column and show it selected by row selection

Here is use case scenarios:
1. A column with radio button. At a single point of time only one radio button should be shown selected in that column.
2. Selecting the radio button will select that row and vice-versa.

Point no. 1 is achieved by simply drag and drop of selectBooleanRadio component.


 <af:column headerText="Select" id="cs4" rowHeader="true" width="50">       <af:selectBooleanRadio text="" label="Label 1" group="RadioButtons"                                 id="sbr1"/> </af:column>
 Remember to add group="RadioButtons" attribute.

For point no. 2 we have to make a javaScript call.
And here is the required code in jspx or jsff.
  <af:resource type="javascript" source="/js/custom.js"/>
And in custom.js add these Lines.

function rowSelectionListener(evt) {
    var table = evt.getSource();
    var selectedRowKey;
    for (key in table.getSelectedRowKeys()) {
        table.findComponent('sbr1', key).setValue(false);
        selectedRowKey = key;
        break;
    }
    table.findComponent('sbr1', selectedRowKey).setValue(true);

Special thanks for point 2 goes to ADF Goodies.
Here is the Link

Monday, 22 December 2014

Insert new row at the end of an ADF Table

In some of case you may want to insert a new row at the end of the table then this method will come handy.

 public String CreateInsert() { 
DCBindingContainer bindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
        DCIteratorBinding dcIterBind =
            (DCIteratorBinding)bindings.get("EmployeeView1Iterator");
        Row newRow = dcIterBind.getViewObject().createRow();
        newRow.setNewRowState(Row.STATUS_INITIALIZED);
        ViewObject vo = dcIterBind.getViewObject();
        vo.last();
        // to insert row at the end of the table
        vo.next();
        vo.insertRow(newRow);
        return null; 

}

Wednesday, 26 November 2014

Useful shortcut keys for Jdeveloper and Oracle ADF

Here are few Jdeveloper shortcuts that can come handy while development [ mostly for Jdev 12c }
  1. Surround with popUp :  ALT+Shift+Z
  2. System.out.println(); : sop+Ctrl+Enter

JSF Lifecycle in short

  1. JSF Restore View: First phase receives the page request from JSF servlet and attempts to find and restore server side components state (A set of server side memory objects that builds the server side hierarchical page structure.). If view can't found as identified by requested view id , a new view is created on the server and the current page's view is stored in FacesContext static object.
  2. Apply request values: The requested values are read and converted to the data type requested by underlying model attributes. The values are accessed from UI components submitted values and passed to local value. When an input component's immediate attribute is set to true, its component validation is performed and component's listeners are executed within this phase. This is one of two phases in which page navigation can occur.
  3. Process Validation: Components are validated for missing data. At the end of this phase value change events are fired.
  4. Update Model Values: Model is updated with the validated value of UI components local values. Then local values of UI components are discarded.
  5. Invoke Application: During this phase , all application level events such as Form Submits are executed. This phase also executes a view layer logic that is stored in action listeners. Page navigation can occur in this phase.
  6. Render Response: Prepares the page view for display on client (Browser). If page view is called for first time, then restore view phase directly passed control to this phase.

Wednesday, 2 July 2014

working with ADF af:inputListOfValues

By default this component will provide an editable inputText , where user can edit value . In some cases we don't want to give this functionality, we just want to give functionality to select the values.
for this we have to make
editMode="select"