I have a <tr:table value="#{mybean.tableValue} binding="#{mybean.tableBinding}">
that i want to show with the selection multiple enabled.
I'm using a List for the collection and the values are take from database when i selected a value from a <tr:selectManyCheckbox>
valueChangeListener with partial triggers.
For each row returned, if some value is true, i want this row marked as selected in the <tr:table value="#{mybean.tableValue} binding="#{mybean.tableBinding}">
I think the problem is that my binding value is not updating when the valueChangeEvent runs inspite of i put binding.setValue the results of database (i checked that the binding.getRowCount()
not equal than mybean.tableValue.size()
) and then the values selected are not correct)
Any idea why the binding rowCount is not equal the value of table?
UPDATE:
<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();
}
}
Thanks!
Solved! I changed the valueChangeListener:
public void valuesChangeListener(ValueChangeEvent event) {
if (event != null) {
List<Integer> valores = (List<Integer>) event.getNewValue();
data2Values.addAll(databaseDAO.search(valores));
tableBinding.getSelectedRowKeys().clear;
tableBinding.setValue(data2Values);
for (int x = 0; x < tableBinding.getRowCount(); x++) {
dataEntity row = (dataEntity) tableBinding.getRowData(x);
tableBinding.setRowIndex(x);
Object key = tableBinding.getRowKey();
if (row.isTrue()) {
tableBinding.getSelectedRowKeys().add(key);
} else {
tableBinding.getSelectedRowKeys().remove(key);
}
}
tableBinding.setVar("item");
FacesContext context = FacesContext.getCurrentInstance();
context.renderResponse();
}
}