Table 组件使用指南:定制SelectionListener

来源:互联网 发布:cba周琦数据统计 编辑:程序博客网 时间:2024/06/14 10:46
运行环境:JDeveloper 11.1.2.1.0 + Oracle Database 10g Express Edition 10.2.0.1。

Table的默认Selection Listener形如:selectionListener="#bindings.JobsView1.collectionModel.makeCurrent}"。
有时我们需要定制化Table的Selection Listener,比如在makeCurrent执行前后加入自己的逻辑。
这就需要把Selection Listener指向Managed Bean中的一个方法,比如:
selectionListener="#{backingBeanScope.myBackingBean.tableSelectionListener}" 。
然后在该方法中用代码实现makeCurrent功能,并在其前后加入自己的逻辑。

重点步骤说明:

1. 修改Table的Selection Listener,指向Managed Bean中的方法

2. Managed Bean的完整代码
package view;import javax.faces.event.ActionEvent;import oracle.adf.model.BindingContext;import oracle.adf.model.binding.DCIteratorBinding;import oracle.adf.view.rich.component.rich.data.RichTable;import oracle.binding.BindingContainer;import oracle.jbo.Key;import oracle.jbo.Row;import oracle.jbo.uicli.binding.JUCtrlHierBinding;import oracle.jbo.uicli.binding.JUCtrlHierNodeBinding;import org.apache.myfaces.trinidad.event.SelectionEvent;import org.apache.myfaces.trinidad.model.CollectionModel;import view.util.ADFUtils;import view.util.JSFUtils;public class MyBackingBean {    public MyBackingBean() {        super();    }    public void tableSelectionListener(SelectionEvent selectionEvent) {        System.out.println("############# Before Make Current Row of Table #############");        makeCurrentRow(selectionEvent);        System.out.println("############# After Make Current Row of Table #############");       }    public void printButton_ActionListener(ActionEvent evt) {        BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();        DCIteratorBinding iter = (DCIteratorBinding)bindings.get("JobsView1Iterator");        Row row = iter.getCurrentRow();        System.out.println("############## The Selected Row Data: " + row.getAttribute("JobId") + " " + row.getAttribute("JobTitle"));    }   private static void makeCurrentRow(SelectionEvent selectionEvent) {        RichTable rt = (RichTable)selectionEvent.getSource();        CollectionModel cm = (CollectionModel)rt.getValue();        JUCtrlHierBinding tableBinding = (JUCtrlHierBinding)cm.getWrappedData();        DCIteratorBinding iter = tableBinding.getDCIteratorBinding();        JUCtrlHierNodeBinding selectedRowData = (JUCtrlHierNodeBinding)rt.getSelectedRowData();        Key rowKey = selectedRowData.getRowKey();        iter.setCurrentRowWithKey(rowKey.toStringFormat(true));        Row row = selectedRowData.getRow();        System.out.println("%%%%%%%%%%%%%%% The Selected Row Data: " + row.getAttribute("JobId") + " " + row.getAttribute("JobTitle"));    }  }


3. 如何获取Table的当前行数据
在上面的代码中,我分别使用了两种方式获取Table的当前行数据:
(1)已经获得了RichTable对象
可以调用RichTable.getSelectedRowData()方法,然后在调用getRow()方法获取行对象,最后获取行对象的每个Attribute。
(2)如果无法获得RichTable对象,可以从DCIteratorBinding查找Table绑定的Iterator,然后调用getCurrentRow()获取当前行对象。
原创粉丝点击