Table 组件使用指南之六:定制SelectionListener
2014-08-20 19:33
501 查看
运行环境: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的完整代码
3. 如何获取Table的当前行数据
在上面的代码中,我分别使用了两种方式获取Table的当前行数据:
(1)已经获得了RichTable对象
可以调用RichTable.getSelectedRowData()方法,然后在调用getRow()方法获取行对象,最后获取行对象的每个Attribute。
(2)如果无法获得RichTable对象,可以从DCIteratorBinding查找Table绑定的Iterator,然后调用getCurrentRow()获取当前行对象。
Project 下载:ADF_Table_SelectionListener.7z
参考文献:
1. http://www.oracle.com/technetwork/developer-tools/adf/learnmore/23-generic-table-selection-listener-169162.pdf http://maping930883.blogspot.com/2010/04/adf076table-selectionlistener.html
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()获取当前行对象。
Project 下载:ADF_Table_SelectionListener.7z
参考文献:
1. http://www.oracle.com/technetwork/developer-tools/adf/learnmore/23-generic-table-selection-listener-169162.pdf http://maping930883.blogspot.com/2010/04/adf076table-selectionlistener.html
相关文章推荐
- Table 组件使用指南:定制SelectionListener
- Table 组件使用指南之十二:定制列字段过滤组件
- Table 组件使用指南:定制列字段过滤组件
- Table 组件使用指南:修改默认排序规则
- Table 组件使用指南:使用CheckBox组件保存和显示Boolean类型字段
- Table 组件使用指南之八:导出Table数据时保持原有数据格式
- Tree组件使用指南之三:定制SelectionListener
- Table 组件使用指南之十七:根据EO的状态设置Row的背景色
- Table 组件使用指南之九:修改默认排序规则
- Table 组件使用指南:增加Column Footer Sum
- Table 组件使用指南之十一:列字段过滤功能
- Table 组件使用指南之七:获取选中的Rows
- Table 组件使用指南之十六:动态增加Column
- Table 组件使用指南:使用Poll组件刷新Table
- Table 组件使用指南之四:使用CheckBox组件保存和显示Boolean类型字段
- Table 组件使用指南:获取选中的Rows
- Table 组件使用指南:基于Table的CRUD
- Table 组件使用指南:列字段过滤功能
- Table 组件使用指南:动态增加Column
- Table 组件使用指南之十五:使用POJO绑定并实现排序与过滤功能