Wednesday, March 25, 2015

ADF table detail stamp set expanded row as a current row and close others expanded rows

I got a lot of questions about table detail stamp how user can set the expanded row to be the current row and closing any other expanded rows (one row will be expanded at a time).

To do that follow this steps:

1- In .jspx select the table and go to property and set RowDisclosureListener to a method in back bean (e.g method name will be rowDisclosureListener)

2- In back bean write this code

public void rowDisclosureListener(RowDisclosureEvent rowDisclosureEvent)
{
RichTable table = (RichTable) rowDisclosureEvent.getSource();
RowKeySet discloseRowKeySet = table.getDisclosedRowKeys();
RowKeySet lastAddedRowKeySet = rowDisclosureEvent.getAddedSet();
Iterator lastAddedRowKeySetIter = lastAddedRowKeySet.iterator();
if (lastAddedRowKeySetIter.hasNext())
{
discloseRowKeySet.clear();
Object lastRowKey = lastAddedRowKeySetIter.next();
discloseRowKeySet.add(lastRowKey);
makeDisclosedRowCurrent(table, lastAddedRowKeySet);
AdfFacesContext adfFacesContext = null;
adfFacesContext = AdfFacesContext.getCurrentInstance();
adfFacesContext.addPartialTarget(table.getParent());
}
}
private void makeDisclosedRowCurrent(RichTable table, RowKeySet keySet)
{
table.setSelectedRowKeys(keySet);
CollectionModel tableModel = (CollectionModel) table.getValue();
JUCtrlHierBinding tableHierBinding = null;
tableHierBinding = (JUCtrlHierBinding) (tableModel).getWrappedData();
DCIteratorBinding dCIteratorBindin = null;
dCIteratorBindin = tableHierBinding.getDCIteratorBinding();
Iterator keySetIter = keySet.iterator();
List firstKey = (List) keySetIter.next();
oracle.jbo.Key key = (oracle.jbo.Key) firstKey.get(0);
dCIteratorBindin.setCurrentRowWithKey(key.toStringFormat(true));
}
view raw Disclosure.java hosted with ❤ by GitHub


3- Run your application and expand any row you will find the expanded row become current row and close any other expanded row

3 comments:

  1. Hi Sameer,

    Thanks for posting the solution.

    I was exactly looking for this functionality. Your solution worked perfectly for me.

    Keep up the good work.
    Many Thanks and

    Kind Regards,
    Bilal

    ReplyDelete