The first pic shows the selection of two checkboxes in a datatable. There were two rows of the datatable shown. At the first checkbox of the row you can see the brackets of the selection list. The only action were the selection of the checkboxes. Nothing more.
Now, when I reload the page or click on the button at the botton, the state changes like in the second pic.
Only the selection of the last row checkboxes are in the selection list. So I m thinking about, if it is a problem with the selection list and its managed bean.
I tried a changelistener on the checkbox but I cant get the status of the checkbox, checked or unchecked. So I removed it again.
<p:datatable>...
<p:rowExpansion>#{pathSearch.selectedSignalList1}
<p:selectManyCheckbox id="signalSel" value="#{pathSearch.selectedSignalList1}">
<p:ajax listener="#{pathSearch.changeSignalListener1}" />
<f:selectItems value="#{pathDistSel.availableSignalList}"
var="sig" itemValue="#{sig.label}___#{sig.idS}" itemLabel="#{sig.label}" />
</p:selectManyCheckbox>
</p:rowExpansion>
Bean snippet
@ManagedBean
@SessionScoped
public class PathSearch implements Serializable {
private List<Signal> selectedSignalList1;
getter, setter...
}
I would be happy, if someone has an idea, where my mistake in thinking is. Perhaps you have an example of something like this.
By using
<p:selectManyCheckbox id="signalSel" value="#{pathSearch.selectedSignalList1}">
<p:ajax listener="#{pathSearch.changeSignalListener1}" />
<f:selectItems value="#{pathDistSel.availableSignalList}"
var="sig" itemValue="#{sig.label}___#{sig.idS}" itemLabel="#{sig.label}" />
</p:selectManyCheckbox>
In the row expansion, the selection list in each row points to the same property, selectedSignalList1
. You need to use a list/array there with the row index as a key, or a hashmap and a business key. So something like
<p:datatable ... rowIndex="signalIndex">
<p:selectManyCheckbox id="signalSel" value="#{pathSearch.selectedSignalList[signalIndex]}">
<p:ajax listener="#{pathSearch.changeSignalListener}" />
<f:selectItems value="#{pathDistSel.availableSignalList}"
var="sig" itemValue="#{sig.label}___#{sig.idS}" itemLabel="#{sig.label}" />
</p:selectManyCheckbox>
</datatable>
And in the bean
@ManagedBean
@SessionScoped
public class PathSearch implements Serializable {
private ArrayList<List<Signal>> selectedSignalList = new ArrayList<>();
getter, setter...
}
This way, each p:selectManyCheckbox
in the p:rowexpansion
has its own list backing the local selection
What you do on submission and how to aggregate or restore when you need to load the submitted data e.g. from a database and show it on screen is up to you to implement.