Reputation: 1679
XHTML file:
<p:tab title="firstTab" id="FT">
<p:dataTable var="..." value="#{...}" id="firstTable" selectionMode="multiple"
selection="#{myController.selectedRows}">
<p:column>...</p:column>
<p:column>...</p:column>
<p:commandButton value="View" action="#myController.viewSelected}"/>
</p:dataTable>
</p:tab>
<p:tab title="secondTab" id="ST">
<p:dataTable var="..." value="#{...}" id="secondTable" selectionMode="multiple"
selection="#{myController.selectedRows}">
<p:column>...</p:column>
<p:column>...</p:column>
<p:commandButton value="View" action="#myController.viewSelected}"/>
</p:dataTable>
</p:tab>
Managed Bean:
@ManagedBean
@RequestScoped
public class MyController{
MyObject[] selectedRows;
//get+set
public void viewSelected(){
System.out.println(selectedRows.length)
}
}
The console output varies. Sometimes the output is 0 but usually the selectedRows content gets messed up. The result is mixed if i have selections in both dataTable-s and press one of the two commandButton-s. I'm guessing that this is happening because there isn't a specific id for the buttons or maybe i should use different business attributes for every dataTable. Which is the correct solution for this problem?
Thanks!
Upvotes: 0
Views: 321
Reputation: 5096
What PF version are you using?
Also if that commandButton
isn't inside a column or anything else, what's the deal with him?
If you want to be a dataTable footer you have to do like this:
<f:facet name="footer">
<p:commandButton value="View" action="#myController.viewSelected}"/>
</facet>
The way you are assigning the selected rows from both dataTables to the same array, I'd say this isn't a good practice, in fact I have never seen something like this! What's point? Even you would like to have two dataTables with the same records, you should at least assign a different array/list
for selected records in each table and put them in different forms
if you don't want to trigger both events on pressing just a commandButton...
Upvotes: 1