如何检索woodstock表的选定行

时间:2023-01-19 09:17:24

I have a JSF woodstock table with checkboxes. When a row is selected I want to do some processing with those items. I managed to get a selection of RowKey objects but can't find out how to get the original objects I put in back. The table is populated by an ObjectListDataProvider.

我有一个带复选框的JSF woodstock表。选择行时,我想对这些项目进行一些处理。我设法获得了一些RowKey对象,但无法找到如何获取我放回来的原始对象。该表由ObjectListDataProvider填充。

2 个解决方案

#1


1  

Always nice to be able to answer you own questions. I managed to solve it by casting the table's data provider to ObjectListDataProvider and use the method 'getObject' to get my original object back.

总是很高兴能够回答你自己的问题。我设法通过将表的数据提供程序转换为ObjectListDataProvider来解决它,并使用方法'getObject'来获取我的原始对象。

#2


0  

So I stumbled across this and was hoping to find how to actually do the selecting and get the row information. I eventually figured it out and I thought others might benefit from how I did it.

所以我偶然发现了这一点,并希望找到如何实际选择并获取行信息。我最终想出来了,我认为其他人可能会从我的表现中受益。

I added a RadioButton to a table column in the JSP and added a valueChangeListener

我将一个RadioButton添加到JSP中的表列,并添加了一个valueChangeListener

<ui:radioButton id="radioButton1" name="radioButton-group1" valueChangeListener="#{MyBeanPage.radioButton1_processValueChange}" />

In my Java code I created the valueChangeListener function and stored the current row information.

在我的Java代码中,我创建了valueChangeListener函数并存储了当前的行信息。

public void radioButton1_processValueChange(ValueChangeEvent event) {
  TableRowDataProvider trdp = (TableRowDataProvider)getValue("#{currentRow}");
  setCurrentRowKey(trdp.getTableRow());  //Sets an instance variable for the RowKey
}

Now if you have any buttons that want to manipulate the data in the selected row you can do this to get the object data. Jasper mentioned this above.

现在,如果您有任何想要操纵所选行中数据的按钮,则可以执行此操作以获取对象数据。贾斯珀在上面提到了这一点

/*getObjectListDataProviderImpl() returns the implementation of 
 *ObjectListDataProvider for your dynamic data.
 */
getObjectListDataProviderImpl().getObject(getCurrentRowKey()); 

You might be able to use something like selectedValue attribute for radio button in conjunction with something else instead of doing valueChangeListener and avoid having to do a valueChange function but this worked so I didn't care to figure out another way.

你可能能够使用像单选的selectValue属性和其他东西一起使用而不是使用valueChangeListener并避免必须执行valueChange函数,但这样做有效,所以我不想弄清楚另一种方法。

#1


1  

Always nice to be able to answer you own questions. I managed to solve it by casting the table's data provider to ObjectListDataProvider and use the method 'getObject' to get my original object back.

总是很高兴能够回答你自己的问题。我设法通过将表的数据提供程序转换为ObjectListDataProvider来解决它,并使用方法'getObject'来获取我的原始对象。

#2


0  

So I stumbled across this and was hoping to find how to actually do the selecting and get the row information. I eventually figured it out and I thought others might benefit from how I did it.

所以我偶然发现了这一点,并希望找到如何实际选择并获取行信息。我最终想出来了,我认为其他人可能会从我的表现中受益。

I added a RadioButton to a table column in the JSP and added a valueChangeListener

我将一个RadioButton添加到JSP中的表列,并添加了一个valueChangeListener

<ui:radioButton id="radioButton1" name="radioButton-group1" valueChangeListener="#{MyBeanPage.radioButton1_processValueChange}" />

In my Java code I created the valueChangeListener function and stored the current row information.

在我的Java代码中,我创建了valueChangeListener函数并存储了当前的行信息。

public void radioButton1_processValueChange(ValueChangeEvent event) {
  TableRowDataProvider trdp = (TableRowDataProvider)getValue("#{currentRow}");
  setCurrentRowKey(trdp.getTableRow());  //Sets an instance variable for the RowKey
}

Now if you have any buttons that want to manipulate the data in the selected row you can do this to get the object data. Jasper mentioned this above.

现在,如果您有任何想要操纵所选行中数据的按钮,则可以执行此操作以获取对象数据。贾斯珀在上面提到了这一点

/*getObjectListDataProviderImpl() returns the implementation of 
 *ObjectListDataProvider for your dynamic data.
 */
getObjectListDataProviderImpl().getObject(getCurrentRowKey()); 

You might be able to use something like selectedValue attribute for radio button in conjunction with something else instead of doing valueChangeListener and avoid having to do a valueChange function but this worked so I didn't care to figure out another way.

你可能能够使用像单选的selectValue属性和其他东西一起使用而不是使用valueChangeListener并避免必须执行valueChange函数,但这样做有效,所以我不想弄清楚另一种方法。