Friday 22 May 2015

OAF: How to handle SelectAll / SelectNone on a table region in Oracle Application Framework

Some time we need to handle to SelectAll / Select None clicks or even the single Selection to do some extra logic. It is not easy to capture those events and you cannot add a firePartialAction to those components declaratively (I haven't researched is there an option to add firePartialAction programmatically). In this post I will explain an easy way to achieve this functionality. 

In this approach we are not using the multipleSelection feature of the table/advancedTable region. Instead we create a custom column and custom Select All/Select None links.

In the example we are using a viewObject TestVO with a simple query and a transient attribute "SelectAttr" for the selection.
  • Add a messageCheckBox as the first column in the table and associate the attribute 'SelectAttr'. Set the Checked Value to 'Y', Unchecked Value to 'N', Action Type to 'firePartialAction' and Event to 'Select'.

  • Add the tableAction region to the table. [Right click on the table, New --> tableActions].
  • Create a RowLayoutRegion in the tableAction region and add the below components:
          Item1(SelectAllLink):
                                   Item Style: link
                                   Text: Select All
                                   Action Type: firePartialAction
                                   Event: SelectAll
          Item2(Spacer1):
                                   Item Style: spacer
                                   Width: 3
          Item3(Separator):
                                   Item Style: rawText
                                   Text: |
          Item4(Spacer2):
                                   Item Style: space
                                   Width: 3
          Item5(SelectNoneLink):
                                   Item Style: link
                                   Text: Select All
                                   Action Type: firePartialAction
                                   Event: SelectAll
  • Now we can handle the CheckBox and the Select All and Select None events in the Controller.
  • To handle the SelectAll event use the below code.The first method updates all rows in the VO. The second method updates only the rows in Range (which means only the once we see on the screen, based on the 'Records Displayed' property of the table).
 if("SelectAll".equals(eventParam)) {  
      OAViewObjectImpl testVO = (OAViewObjectImpl)appModule.findViewObject("TestVO1");  
      RowSetIterator rowSetIterator = testVO.createRowSetIterator("TestIter");  
      rowSetIterator.reset();  
      while (rowSetIterator.hasNext()){  
           Row row = rowSetIterator.next();  
           row.setAttribute("SelectAttr","Y");  
      }  
      rowSetIterator.closeRowSetIterator();  
 }  
 if("SelectAll".equals(eventParam)) {  
      OAViewObjectImpl testVO = (OAViewObjectImpl)appModule.findViewObject("TestVO1");  
      Row rows[] = testVO.getAllRowsInRange();  
      for(Row row : rows){  
           row.setAttribute("SelectAttr","Y");  
      }  
 }  
    • To handle the SelectNone event use the below code.The first method updates all rows in the VO. The second method updates only the rows in Range (which means only the once we see on the screen, based on the 'Records Displayed' property of the table).

     if("SelectNone".equals(eventParam)) {  
          OAViewObjectImpl testVO = (OAViewObjectImpl)appModule.findViewObject("TestVO1");  
          RowSetIterator rowSetIterator = testVO.createRowSetIterator("TestIter");  
          rowSetIterator.reset();  
          while (rowSetIterator.hasNext()){  
               Row row = rowSetIterator.next();  
               row.setAttribute("SelectAttr","N");  
          }  
          rowSetIterator.closeRowSetIterator();  
     }  
    
     if("SelectNone".equals(eventParam)) {  
          OAViewObjectImpl testVO = (OAViewObjectImpl)appModule.findViewObject("TestVO1");  
          Row rows[] = testVO.getAllRowsInRange();  
          for(Row row : rows){  
               row.setAttribute("SelectAttr","N");  
          }  
     }  
    
    • To handle the check box Select, use the below code.
     if ("Select".equals(eventParam)){  
           String eventRowSourceParam = pageContext.getParameter(EVENT_SOURCE_ROW_REFERENCE);  
           Row row = appModule.findRowByRef(eventRowSourceParam);  
     }  
    

    • In the below screen shot you can see both the Standard and the Custom Links. The one marked in Yellow color is the custom ones.
    • When you remove the Stanadard multiSelection on the table, the page will look like below (infact you save some space as well :)).
    The pages (PG.xml and CO.java) used for the above demo can be downloaded from here.

    Feel free to point out if anything is missing/wrong in this blog.

    2 comments:

    1. Hi...
      How remove the Stanadard multiSelection on the table?

      ReplyDelete
    2. Hi, How to handle Multi Selection in Details Advanced table (Advanced table (Master) in Advanced table (Details)). Master Checkbox is holding the checkbox but, Details Check box is getting unchecked on button submission. Please let us know what can be done for details checkbox.

      ReplyDelete