我有一个<tr:table value="#{mybean.tableValue} binding="#{mybean.tableBinding}">
我想在启用选择多个的情况下显示。<tr:selectManyCheckbox>
我正在为集合使用列表,当我从带有部分触发器的 valueChangeListener 中选择一个值时,这些值是从数据库中获取的。
对于返回的每一行,如果某个值为真,我希望在<tr:table value="#{mybean.tableValue} binding="#{mybean.tableBinding}">
我认为问题是当valueChangeEvent运行时我的绑定值没有更新,尽管我把binding.setValue数据库的结果(我检查了binding.getRowCount()
不等于mybean.tableValue.size()
)然后选择的值不正确)
知道为什么绑定 rowCount 不等于表的值吗?
更新:
<tr:subform id="subform1">
<tr:panelFormLayout rows="6">
<tr:selectManyCheckbox id="val1" label="Values"
layout="horizontal" value="#{mybean.data1Values}"
autoSubmit="true" valueChangeListener="#{mybean.valuesChangeListener}">
<f:selectItems value="#{mybean.list1Values}"/>
</tr:selectManyCheckbox>
</tr:panelFormLayout>
</tr:subform>
<tr:spacer width="5px"/>
<tr:subform id="subform2">
<tr:table rows="0" partialTriggers=":::subform1:val1 "
value="#{mybean.data2Values}" var="item" id="tabladatos" width="75%"
rowSelection="multiple" rowBandingInterval="1" binding="#{mybena.tableBinding}"
verticalGridVisible="true" horizontalGridVisible="true">
<tr:column id="_head1" headerText="Colum1" width="30%">
<tr:outputText id="_head1_value" value="#{item.value1}"/>
</tr:column>
<tr:column id="_head2" headerText="Colum2" width="30%">
<tr:outputText id="_head2_value" value="#{item.value2}"/>
</tr:column>
</tr:table>
</tr:subform>
public void valuesChangeListener(ValueChangeEvent event) {
if (event != null) {
List<Integer> valores = (List<Integer>) event.getNewValue();
data2Values.addAll(databaseDAO.search(valores));
RowKeySet rks = new RowKeySetImpl();
rks.clear();
tableBinding.setSelectedRowKeys(rks);
tableBinding.setValue(data2Values);
for (int x = 0; x < tableBinding.getRowCount(); x++) {
dataEntity row = (dataEntity) tableBinding.getRowData(x);
tableBinding.setRowIndex(x);
if (row.isTrue()) {
Object key = tableBinding.getRowKey();
rks.add(key);//tableBinding.getSelectedRowKeys().add(key);
} else {
//do something
}
}
tableBinding.setVar("item");
tableBinding.setSelectedRowKeys(rks);
FacesContext context = FacesContext.getCurrentInstance();
context.renderResponse();
}
}
谢谢!