I'm quite new to PrimeFaces and JSF in general and I couldn't find a topic with similar situation. I checked I have no nested forms. Seems like I'm running into some weird behaviour - at least I have no idea why it does what it does ;)
Let's say I have a List. Class 'Module' has a List. My intention is to show data in a table, nicely grouped by module and elements in rows under it. Seemed like subtable was my wish come true, but I found out it's only for reporting issues, so it's not selectable. Unfortunately I need to know the selection to run actions like 'Delete' or 'Edit' on an module. I tried to place a button in subtable facet with an actionlistener setting the current object in backing bean and then opening a dialog to offer further actions (on selected module). I first thought it works, but then noticed that pressing the same button, a randomly module object was transfered into backing bean.
<p:dataTable id="displayModules" var="displayModuleBean"
value="#{displayModuleController.displayModuleBeans}"
emptyMessage="Es existieren keine Module für diese Kampagne.">
<p:row>
<p:column headerText="Vermarkter" />
<p:column headerText="Platzierung" />
<p:column headerText="Umfeld" />
<p:column headerText="Format(e)" />
<p:column headerText="Startdatum" />
<p:column headerText="Enddatum" />
<p:column headerText="Abrechnungsart" />
</p:row>
<p:subTable id="displayModuleElements" var="displayModuleElement"
value="#{displayModuleBean.moduleElements}"
sortBy="#{displayModuleBean.module.name}" sortOrder="descending">
<f:facet name="header" style="vertical-align: middle">
#{displayModuleBean.module.name}
<p:commandButton alt="Modul bearbeiten" icon="ui-icon-pencil"
style="float:right"
actionListener="#{displayModuleController.setSelectedDisplayModuleBean(displayModuleBean)}"
oncomplete="displayModuleEditDialog.show();"
update=":tabview:displayModulesDialogForm:editDisplayModules">
</p:commandButton>
</f:facet>
<p:column headerText="Vermarkter">
<h:outputText value="#{displayModuleElement.advertiserName}" />
</p:column>
</p:subTable>
</p:dataTable>
Backing Bean (DisplayModuleController, SessionScoped):
public void setSelectedDisplayModuleBean(ModuleBean selectedDisplayModuleBean)
{
this.selectedDisplayModuleBean = selectedDisplayModuleBean;
this.setSelectedDisplayModuleName(this.selectedDisplayModuleBean != null ? this.selectedDisplayModuleBean.getModule().getName()
: null);
this.addFacesMessage(FacesMessage.SEVERITY_INFO, "Set selected ModuleBean: ",
this.selectedDisplayModuleBean != null ? this.selectedDisplayModuleBean.getModule().getName() : "keins");
}
I even tried a workaround with an Accordion Panel and Datatables on each tab, but I'm ending at the same weird behaviour. I also tried adding a button in each row to transfer the selected element itself (not the parent module), but that works exactly the same randomly way.
What the hell am I missing? Would be great if someone could help me to get on the right way ;)
I'm using: PrimeFaces 4.0, MyFaces 2.1.13, Apache Tomcat 7.0.42
LG, Ani