您的位置:首页 > 其它

How to use listeners on ADF Table Tree TreeTable

2017-09-26 14:19 375 查看
set the property Table.rowselection to multiple. when page is runing , use ctrl/shift to select multiple rows.
1.How to get the rows user selected , sample:mBean
import oracle.jbo.uicli.binding.JUCtrlHierNodeBinding; import oracle.jbo.Row; import org.apache.myfaces.trinidad.component.UIXCollection; import org.apache.myfaces.trinidad.model.RowKeySet; ……       private RichTable table;//binding with table on the page       public String findAllSelectedRows_action() {         RowKeySet rks = table.getSelectedRowKeys();         iteratorRKS(rks, table);         return null;     }       public void iteratorRKS(RowKeySet rks, UIXCollection collection) {//public method that can be used in iterator tree/table/treeTable         Iterator it = rks.iterator();         List<Row> list = new ArrayList<Row>();         System.out.println("---------mBean--------start print selected rows with all attribtue-----------------");         while (it.hasNext()) {             Object rowKey = it.next();             collection.setRowKey(rowKey);             JUCtrlHierNodeBinding node = (JUCtrlHierNodeBinding)collection.getRowData();             String[] strs = node.getAttributeNames();             for (String str : strs) {                 System.out.print(str + ":" + node.getAttribute(str) + " ");             }             System.out.println();             //put selected rows into AM by a list             list.add(node.getRow());         }         System.out.println("---------mBean--------end print selected rows-----------------");         Map map = new HashMap();         map.put("selectList", list);         BindingContainer bindings = getBindings();         OperationBinding operationBinding = bindings.getOperationBinding("findAllSelectedRows");         operationBinding.getParamsMap().put("map", map);         operationBinding.execute(); } ……  
AM:
    public Map findAllSelectedRows(Map map) {         List<Row> selectList = (List<Row>)map.get("selectList");         System.out.println("-------------------start print in AM-------------------");         for (Row row : selectList) {             System.out.println(row.getAttribute(0));         }         System.out.println("-------------------end print in AM-------------------");         return null; }  
 
How to use this in treemBean:
import oracle.jbo.uicli.binding.JUCtrlHierNodeBinding; import org.apache.myfaces.trinidad.component.UIXCollection; import org.apache.myfaces.trinidad.event.SelectionEvent; import org.apache.myfaces.trinidad.model.RowKeySet; ……   private RichTree tree;       public String tree_action2() {         RowKeySet rks = tree.getSelectedRowKeys();         iteratorRKS(rks, tree);         return null; }       public void iteratorRKS(RowKeySet rks, UIXCollection collection) {         Iterator it = rks.iterator();         while (it.hasNext()) {             Object rowKey = it.next();             collection.setRowKey(rowKey);             JUCtrlHierNodeBinding node = (JUCtrlHierNodeBinding)collection.getRowData();             //start iterator             String[] strs = node.getAttributeNames();             for (String str : strs) {                 System.out.print(str + ":" + node.getAttribute(str) + " ");             }             System.out.println();             //         } } ……  
So with treeTable

2.How to listen to the user select, sample 1:[/b]mBean
    public void selectionListener(SelectionEvent selectionEvent) {//binding with table.selectionListener         RowKeySet rks = selectionEvent.getAddedSet();         System.out.println("new selected rows:------------");         iteratorRKS(rks, table);//         RowKeySet rks2 = selectionEvent.getRemovedSet();         System.out.println("new deselected rows:------------");         iteratorRKS(rks2, table);     }
  3.How to listen to the user select, sample 2:[/b]
mBean
        MySelectEvent mse=new MySelectEvent();         table.addSelectionListener(mse);
MySelectEvent.java
import org.apache.myfaces.trinidad.event.SelectionEvent; import org.apache.myfaces.trinidad.event.SelectionListener;   public class MySelectEvent implements SelectionListener{       public void processSelection(SelectionEvent selectionEvent) {       System.out.println("Class3:"+selectionEvent.getSource()); }   }
 
Suggetsion:if you want process your logic immediatly when user select. Use listener(2 3)!other case use 1.

Original(原创)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: