Monday 19 January 2015

Select All rows in ADF tabel

I got a requirement to provide 'Select All' option for ADF table. Tried a lot in different ways and finally got the solution with the following approach.

Code in UI:
 
<af:commandToolbarButton partialSubmit="true" text="Select All" id="cb1"
actionListener="#{myBean.selectAllListener}">
</af:commandToolbarButton> 

Code in the bean for selection listener is like this:
public void selectAllListener() {
  RowKeySet rkset = new RowKeySetImpl();
  CollectionModel model = (CollectionModel)myTable.getValue();
  int rowcount = model.getRowCount();
 
  for (int i = 0; i < rowcount; i++) {
     model.setRowIndex(i);
     Object key = model.getRowKey();
     rkset.add(key);
  }
 
  myTable.setSelectedRowKeys(rkset);
}

When we click on 'Select All' button, it will select all the rows from the model, adds to the selected row keys of the table and also displays the selected row count in the 'Rows selected' section in the status bar.

If the selection listener has makeCurrent entry, then the above approach may fail. When you select one row and then go for 'Select All', this wont work  to overcome this issue you can have selection listener code in the bean as follows:

public void selectAllListener() {
  RowKeySet rkset = myTable.getSelectedRowKeys();
  CollectionModel model = (CollectionModel)myTable.getValue();
  int rowcount = model.getRowCount();
 
  for (int i = 0; i < rowcount; i++) {
     model.setRowIndex(i);
     Object key = model.getRowKey();
     rkset.add(key);
  }
}

This means that, you are going to add remaining rows on top of selected rows.

Wednesday 22 October 2014

RowInconsistentException: JBO-25014: Another user has changed the row with primary key

Caused by: oracle.jbo.RowInconsistentException: JBO-25014: Another user has changed the row with primary key oracle.jbo.Key[25544 ]. Sol: when we try to commit or executeQuery on a row which is already modified and comitted by another vo/am, this issue occurs. so if you know that there are chanses of updating by another vo, then better to commit or rollback the existing changes then do EO clear chache.
 service.getDBTransaction().commit();
 service.getDBTransaction().clearEntityCache("oracle.apps.msc.ascp.itemsimulation.model.entity.ItemAttributesEO");
 mscItemAttributesVO.executeQuery();

How to load external javascript or css files in jsff?

Guys, if you want to use external javascript or css, you can use af:resource tag in jsff page.
<source>
  <af:resource source="/customStyles.css" type="css"></af:resource>
</source>
In-line CSS content:
<source>
  <af:resource type="css">
    DIV.customStyle { color: red; }
  </af:resource>
</source>
Include an external JS file:
<source><  af:resource source="/customCode.js" type="javascript"></af:resource></source>
In-line JavaScript code:
<source>
  <af:resource type="javascript">
    function clientListenerFunction(event)
    {
       // content ...
    }
  </af:resource>
</source>