Non selectable datatable and var attribute

UI Components for JSF
Post Reply
mynca
Posts: 25
Joined: 30 Jun 2011, 11:24

11 Jan 2012, 22:02

Hi,

I have a datatable which is not selectable. So I have no selectionMode, rowKey or selection attribute set.
The datatable contains some rows and at the end of each row a button is placed to edit the row. When clicking this edit button it takes you to another page with the details of the selected row.
When this button is clicked an actionListener is invoked to set the selected object in my backing bean. The object which is given to the actionListener is the value of the var attribute of the datatable.

Code: Select all

<p:dataTable id="socialBalanceTrainingTable" widgetVar="socialBalanceTrainingTable" value="#{socialBalanceTrainingBean.socialBalanceTrainingList}"
                      var="socialBalanceTraining" paginator="true" rows="10" emptyMessage="#{msgs.noRecordsFound}">

     <!-- Collaborator number. -->
     <p:column sortBy="#{socialBalanceTraining.collaboratorInternalNumber}" filterBy="#{socialBalanceTraining.collaboratorInternalNumber}">
          <f:facet name="header">
               <h:outputText id="headerNumber" value="#{msgs.number}"/>
          </f:facet>
          <h:outputText value="#{socialBalanceTraining.collaboratorInternalNumber}"/>
     </p:column>

     <!-- Collaborator. -->
     <p:column sortBy="#{socialBalanceTraining.fullName}" filterBy="#{socialBalanceTraining.fullName}">
          <f:facet name="header">
               <h:outputText value="#{msgs.collaborator}" />
          </f:facet>
          <h:outputText value="#{socialBalanceTraining.fullName}" />
     </p:column>

     <!-- Training description. -->
     <p:column sortBy="#{socialBalanceTraining.trainingDescription}" filterBy="#{socialBalanceTraining.trainingDescription}">
          <f:facet name="header">
               <h:outputText value="#{msgs.trainingDescription}" />
          </f:facet>
          <h:outputText value="#{socialBalanceTraining.trainingDescription}" />
     </p:column>

     <!-- Training hours unpaid. -->
     <p:column>
          <f:facet name="header">
               <h:outputText value="#{msgs.unpaid}" />
          </f:facet>
          <h:outputText value="#{socialBalanceTraining.trainingHoursUnpaid}" />
     </p:column>

     <!-- Training hours paid. -->
     <p:column>
          <f:facet name="header">
               <h:outputText value="#{msgs.paid}" />
          </f:facet>
          <h:outputText value="#{socialBalanceTraining.trainingHoursPaid}" />
     </p:column>

     <!-- Training costs. -->
     <p:column>
          <f:facet name="header">
               <h:outputText value="#{msgs.costs}" />
          </f:facet>
          <h:outputText value="#{socialBalanceTraining.trainingCost}" />
     </p:column>

     <!-- Training type. -->
     <p:column>
          <f:facet name="header">
               <h:outputText value="#{msgs.type}" />
          </f:facet>
          <h:outputText value="#{socialBalanceTraining.trainingType.meaning}" />
     </p:column>

     <!-- Edit button. -->
     <p:column>
          <p:outputPanel>
               <p:commandButton image="ui-icon ui-icon-pencil" action="edit" process="@this" update="@none"
                     actionListener="#{socialBalanceTrainingBean.setSelectedSocialBalanceTraining(socialBalanceTraining)}" />
          </p:outputPanel>
     </p:column>
</p:dataTable>
Now a problem occurs when the filters on the columns are used. If a limit the visable rows by using a filter, then the wrong object is passed to the backing bean.
Maybe a little example will explain:
I have 5 rows in the datable when no filters are used (A, B, C, D and E).
Now I use a filter so the last two rows are shown (D and E). If I click on the edit button of D then object A is passed in the backing bean. If E is clicked then I get B. So Primefaces gives me the wrong object. I assume this is because it gets the object by index.

I assume this is a bug. Does anyone have this problem too or how can i fix it?

Note: If I set the datatable to be selectable and use the p:ajax rowSelect then the SelectEvent in the backing bean gives me the correct selected object. So in this case I have no problem but for my view the datatable should not be selectable.

Grtz,
Mynca
JSF 2.0
Primefaces 3.0.1
Tomcat 7.0

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

13 Jan 2012, 07:36

mynca wrote:So I have no selectionMode, rowKey or selection attribute set.
Hmmm, the showcase example does it like demonstrated below.

Code: Select all

                 <p:commandButton update=":form:display" oncomplete="carDialog.show()" icon="ui-icon-search" title="View">
                     <f:setPropertyActionListener value="#{car}" target="#{tableBean.selectedCar}" />
                 </p:commandButton>
What happens when you remove process="@this"?

Code: Select all

               <p:commandButton image="ui-icon ui-icon-pencil" action="edit" process="@this" update="@none"
                     actionListener="#{socialBalanceTrainingBean.setSelectedSocialBalanceTraining(socialBalanceTraining)}" />
You didn't provide your bean, so we can check that as well.
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

mynca
Posts: 25
Joined: 30 Jun 2011, 11:24

13 Jan 2012, 08:41

Problem solved.

Apparently i had to place the datatable in the process attribute of the commandbutton.
JSF 2.0
Primefaces 3.0.1
Tomcat 7.0

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

13 Jan 2012, 12:38

Good. When your questions are answered, then please update the topics with answer/solution. Someone else may benefit later on. It's very good to search google for forum.primefaces.org ...
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 44 guests