Monday, November 10, 2014

ADF : Programmatic access to View Accessor / Dependent LOV

View Accessor is often used to bring List of Values . In simple way , it is used to access a view object from another view object . why in the world should i need to access the view accessor programmatically when ADF View object has the privilege to handle it automatically.. well , thats a point.. There we have a use case //

In general,dependent LOV based on another attribute gets its value by executing view accessor.suppose i have an attribute whose view accessor is defined but the value which is required to be passed comes from various other action like previous page input. There is no view link between two view objects,no relationship .so its completely two independent view objects, but LOV in VO2 depends on VO1 input ..
























In Vo2RowImpl :

//VA defined

 public RowSet getMoney() {
        return (RowSet)getAttributeInternal(MONEY);
    }

//custom method
public Object executeViewAccessor(String val) {
      RowSet rs=(RowSet)getAttributeInternal(MONEY);
      rs.setNamedWhereClauseParam("str", str);
      rs.executeQuery();        
      return rs;
    }

//Code to invoke the VA from AmImpl class. AM method is the bridge between two taskflow to pass parameters since we added TF2 as region in main TF. you should add the below AmImpl method as method action before PAGE 2 in TF2

AmImpl Method :

public void executeAction(String str) {
       
        ViewObjectImpl vo = this.getVo2();
        Row row = vo.createRow();
        vo.insertRow(row);
        VO2RowImpl rImpl = (VO2RowImpl )vo.getCurrentRow();
        rImpl.executeViewAccessor(str);

    }

Now you have executed the View accessor of Money VO and your attribute in VO2 containing the LOV prepared based on the input being passed.

Note : There could be certainly many ways to achieve this functionality. This is one of the use case to explain ..






Sunday, November 9, 2014

ADF : Conditional Render in ADF Faces/ Manually creating ADF Table display

Use case :

The Employee of a company fills an online form of resigning reason before leaving the organization.
All these comments/reason submitted by various employees who left the organization will be saved in a separate DB table Job History.

Now the list of employees with the feedback  in the UI looks like this


Note: I am constructing these information as a table format without using ADF Table . The reason is to explain the scenario with more of real time case.

To achieve this we can use af:gridrow that can loop over the rows that the iterator has.

<af:iterator value="#{bindings.JobHistory.collectionModel}"    var="row" id="it2"   >
           //Code to loop over the rows
         <af:gridRow>
        <af:gridCell>

        </af:gridCell>
       </af:gridRow>
<af:iterator/>

It just looks like the old jsp code where in the table TR and TD loops over a collection of data.
we generally fix the cell property of the row to fixed to have the limited alignment of the table in the page. The space between each row should be dynamic so that the text in the cells would not get overlapped.

something like this will makes sense

<af:iterator value="#{bindings.JobHistory.collectionModel}"    var="row" id="it2"   >
<af:gridRow id="gr3"height="#{row.comments gt 100 ? '40px' : '20px'}">
 <af:gridCell marginStart="10px" width="100px" id="gc7"       valign="stretch" halign="stretch">
              <af:outputText value="#{row.Name}" id="ot8" noWrap="false"/>
            </af:gridCell>
            <af:gridCell marginStart="10px" id="gc9" width="250px"   valign="stretch" halign="stretch">
              <af:outputText value="#{row.comments}" id="ot10"     inlineStyle="word-wrap:break-word" noWrap="false"/>
            </af:gridCell>
 </af:gridRow>

Also few more EL expressions for the conditional rendering of the ADF Faces components

<af:outputText value="#{pageFlowScope.data.request eq 'YES' and pageFlowScope.data.response eq 'N' ? 'DONE': 'COMPLETED'}"  id="ot3"/>

 <af:outputText value="#{str}" id="ot1" rendered="#{requestContext.flag=='YES'}" />

<af:commandLink id="ci2"     rendered="#{row.flag == 'Y' }"  />

Friday, June 6, 2014

ADF : Accessing column value from ADF table row


There are cases where we need to show only a number in the Ui that comes from a different ViewObject .. Infact the real case scenario is ViewObject that has count(*) as result and we need to print that to the user in a tab or textbox.. look at the example


The Tab displays the Total Countries ..

select countries(*) as Count from COUNTRY group by countries ; This will return a single value..we generally tend to use VO.getEstimatedRowCount to get all the rowvalues and display .. The way to achieve and retrieve this is very simple ...


Following code snippet will help to achieve that

 public int getCount() {

        Long val = 0;
        ViewObject vo = this.getCountryVO();
        vo.executeQuery();
        RowSetIterator rsIterator = vo.createRowSetIterator(null);
        rsIterator.reset();
      
       while (rsIterator.hasNext()) {
            Row row = rsIterator.next();
            val = ((BigDecimal)row.getAttribute("Count1")).longValue();
        }

        rsIterator.closeRowSetIterator();
        return val;

  }

Expose this method in the AM Client Interface .Add this method  to the page bindings as methodAction. Go to executable section in the pagedef , add invokeAction to this method . This will get invoked every time when the page is loaded . This brings the count available during pageload

Add this expr to the place where you need to print the result .
#{bindings.getCount.resul}

You can also access that method directly on clicking some button or link via ActionListener without having to InvokeAction under executables section ...




Monday, May 12, 2014

Select and Unselect All Rows in ADF Table via backing bean


Select :

1) Create a table binding in the backing bean

     CollectionModel model = (CollectionModel)getMessagesTable().getValue();

     getMessagesTable() is the binding method to the adf table.


Actual Code :

 public void selectAllRecords(ActionEvent actionEvent) {
             
        RowKeySet rks = new RowKeySetImpl();
        CollectionModel cm= (CollectionModel)getMessagesTable().getValue();
        int count= cm.getRowCount();
        for (int i = 0; i < count; i++) {
            cm.setRowIndex(i);
            Object key = cm.getRowKey();
             rks.add(key);
       }
     
       
        getCtoMessagesTable().setSelectedRowKeys(rks);
       
   }

Unselect :

The above method will make all the records selected in the UI. we will see how to unselect all the rows.

public void clearAllRecords(ActionEvent actionEvent) {
  
       getMessagesTable().getSelectedRowKeys().clear();

  
   /*       
   //This commented part is just to make sure the selected records are still the same before we clear 

     DCBindingContainer bindings =   (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
        DCIteratorBinding msgIter = bindings.findIteratorBinding("Messages1Iterator");
      
       RowSetIterator msgRSIter = msgIter .getRowSetIterator();
            
       
        RowKeySet rks = getMessagesTable().getSelectedRowKeys();
              

       Iterator it = rks.iterator();
   
        while(it.hasNext()){
           
           
            Key key = (Key)((List)it.next()).get(0);
            System.out.println("Row key:"+key);
            Row currentRow = msgRSIter .getRow(key);
            System.out.println("Config:"+currentRow.getAttribute("Name"));
              
           
            }
           
        */

    
                                                               
       
    }

Friday, January 3, 2014

Change the default view of the af:query panel in the web page


Is it possible to change the default view of the ADF af:query panel in the web page with all the columns appearing in straight line ?

Yes it is possible .  we can actually split it the way we want .

Select af:query in the structure window , go to property inspector , select Appearance tab and change these two parameters.

Rows : 3
MaxColumns : 3

Save your project and run the page. Your page should look like this.