Flipkart Search

Showing posts with label adf table. Show all posts
Showing posts with label adf table. Show all posts

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; 

}

Monday, 31 March 2014

Custom Export to Excel in functionality in Oracle ADF

    public static void exportHtmlTableToExcel(DCIteratorBinding customVO1Iterator) throws IOException {

                String filename = "ExportedExcel.csv";

        customVO1Iterator.setRangeSize(4000);

        //Setup the output

        String contentType = "application/vnd.ms-excel";
        FacesContext fc = FacesContext.getCurrentInstance();
        HttpServletResponse response =
            (HttpServletResponse)fc.getExternalContext().getResponse();
        response.setHeader("Content-disposition",
                           "attachment; filename=" + filename);

        response.setContentType(contentType);
        PrintWriter out = response.getWriter();
        RowSetIterator rsi = customVO1Iterator.getRowSetIterator();
        //    Get the Headers
        String[] attNames = rsi.getRowAtRangeIndex(0).getAttributeNames();

        for (int i = 0; i < attNames.length; i++) {
            if (i > 0)
                out.print(",");
            out.print(attNames[i]);

        }
        out.println();
//Setting the first row data ,was creating problem in my application-- so called reset
                rsi.reset();
        Boolean isFirst = true;
        while (rsi.hasNext()) {
            Row currentRow = null;
            if (isFirst) {
                currentRow = rsi.first();
                isFirst = false;
            } else {
                currentRow = rsi.next();
            }
            if (currentRow != null) {
                Object[] attValues = currentRow.getAttributeValues();
                for (int j = 0; j < attValues.length; j++) {
                    if (j > 0)
                        out.print(",");
                    if (attValues[j] != null)
                        out.print("\"" + attValues[j] + "\"");
                }

            }
            out.println();
        }
        out.close();

        fc.responseComplete();

        customVO1Iterator.setRangeSize(30);

    }

Sunday, 15 April 2012

Showing User Specific Table data in Adf - Part 1

This is a very normal use case where a user has to see his own data. We usually do it by saving userdata in DB according to some UserId{Like emailId } or some specific number or anything...For this tutorial you should have a table with user specific data....For this example I took Employee table of HR schema .....
There are two methods to do this.....
1. Execute with Params{With Bind Variables}
2. ViewObject Implementation Class
In Part 1. I will how to achieve this goal by Execute with Params{With Bind Variables}...
Steps:::
1. First create a desired VO and Bind a variable to it.{This should be the your userId which can be anything}
2. Now give a where clause to your VO which binds your bind Variable

3. Now create a task-flow{or a jspx page}......I prefer taskflow to ensure re usability...

4. Now add a view to it ..and make sure you select document tpye: JSP XML


5. Now go to datacontrol and expand your employee collection and go to operation section and drag and drop ExecuteWithParams to your page as an ADF parameter Form 
6. Now drag and drop your table on the same jsff page see above..
7. Now go to jsff page Bindings and then go to structure window{left below corner}and you can see Executables . Now right click on Executables->Insert Inside executables->invoke Action. Give any string as id and Binds as ExecuteWithParams . Go to its property and make refresh:always {Note: click on the image below for better visibility}



8. Now again go to binding tab of the jsff page{you must be there already }. See the cursor{Means edit the bindings->ExecuteWithParams

9. Now you will see the dialog as below...go to value -> show El  Expression Builder

10. Now delete the existing text and map it to security context user name...
11. Now you can delete the adf parameter form in the jsff page{So that user can't view it}.. or you can make the adf panel form layout render false which contains the ExecuteWithParams form field and Button

12. Now you have to give a login page to the user so that he can give his user name and password to login and see his data...In adf this is very simple...Go to Application->Secure->Configure ADF security...

Follow the next screens as it is--



13. Now click next-next or finish and open Application Resources->Descriptors->META-INF->jazn-data.xml and add your user and give userId as Name
14. Add an application role and add the existing user to this role...

15. Now go to resource Grants tab then Resource Type->Task Flow and give your task grant to application rule..

16. Now create a blank jspx page and drop adf page flow into it as region
17. Now grant this jspx to the same application role....
18. Now run your application and Enjoy
see the sample..earlier
 And now with ExecuteWithParams