您的位置:首页 > 其它

Table 组件使用指南之七:获取选中的Rows

2014-08-20 19:34 459 查看
开发环境:JDeveloper 11.1.2.2.0 + Oracle XE Database 10gR2。

重点步骤说明:

1. 创建一个新页面:table_selected_rows.jsf

(1)设置RowSelection=mutiple,允许多选。

(2)设置Binding,指向Managed Bean中的一个属性。

(3)放置一个按钮,点击按钮,调用Managed Bean中的方法,获取选中的Table行。

2. 完整的Managed Bean代码

package view;

import java.util.Iterator;
import java.util.List;

import javax.faces.event.ActionEvent;

import oracle.adf.view.rich.component.rich.data.RichTable;

import oracle.jbo.Row;
import oracle.jbo.uicli.binding.JUCtrlHierNodeBinding;
import oracle.jbo.uicli.binding.JUCtrlHierBinding;
import oracle.jbo.uicli.binding.JUCtrlHierTypeBinding;

import org.apache.myfaces.trinidad.model.CollectionModel;
import org.apache.myfaces.trinidad.model.RowKeySet;

public class MyBackingBean {
private RichTable table;

public MyBackingBean() {
}

public void printButton_ActionListener(ActionEvent evt) {
RichTable table = this.getTable();
RowKeySet rks = table.getSelectedRowKeys();
Iterator rksIterator = rks.iterator();
while (rksIterator.hasNext()) {
List key = (List)rksIterator.next();
JUCtrlHierBinding tableBinding = null;
CollectionModel collectionModel = (CollectionModel)table.getValue();
collectionModel.setRowKey(key);
tableBinding = (JUCtrlHierBinding)collectionModel.getWrappedData();
JUCtrlHierNodeBinding nodeBinding = tableBinding.findNodeByKeyPath(key);

String[] strs = nodeBinding.getAttributeNames();
for (String str : strs) {
System.out.println("########################### " + str + ":" + nodeBinding.getAttribute(str));
}

Row rw = nodeBinding.getRow();
System.out.println("########################### row " + rw);

String rowType = rw.getStructureDef().getDefName();
System.out.println("########################### rowType " + rowType);

JUCtrlHierTypeBinding typeBinding = nodeBinding.getHierTypeBinding();
String nodeStuctureDefname = typeBinding.getStructureDefName();
System.out.println("########################### nodeStuctureDefname " + nodeStuctureDefname);
}
}

public void setTable(RichTable table) {
this.table = table;
}

public RichTable getTable() {
return table;
}
}


可以看出获取Table的选中行和获取Tree的选中节点的代码(参考《获取选中的Tree节点》)几乎完全一致。

3. 运行效果,按住Ctrl键多选几个节点,然后点击按钮

输出如下:

########################### JobId:SA_MAN

########################### JobTitle:Sales Manager

########################### MinSalary:10000

########################### MaxSalary:20000

########################### row ViewRow [oracle.jbo.Key[SA_MAN ]]

########################### rowType JobsView

########################### nodeStuctureDefname model.JobsView

########################### JobId:PU_MAN

########################### JobTitle:Purchasing Manager

########################### MinSalary:8000

########################### MaxSalary:15000

########################### row ViewRow [oracle.jbo.Key[PU_MAN ]]

########################### rowType JobsView

########################### nodeStuctureDefname model.JobsView

########################### JobId:FI_ACCOUNT

########################### JobTitle:Accountant

########################### MinSalary:4200

########################### MaxSalary:9000

########################### row ViewRow [oracle.jbo.Key[FI_ACCOUNT ]]

########################### rowType JobsView

########################### nodeStuctureDefname model.JobsView

Project 下载:ADF_Table_GetSelectedRow.7z
http://maping930883.blogspot.com/2010/04/adf077table-rows.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: