Datatable: Wrong selection after sorting

UI Components for JSF
Post Reply
3.1415926535
Posts: 7
Joined: 10 Feb 2011, 14:57

10 Feb 2011, 15:20

Hi,
i have a problem with my datatable, after i sort the table by any value and klick on my commandlink at the row, the actionlistener uses the value that was in that row before sorting.

for example: if i have item with ID 36 at first row in table and after sorting item ID 1 at first row. After submit i have item with ID 36 at bean.current.

Code: Select all

...
<p:dataTable rendered="#{bean.rowCount gt 0}" id="table"
	value="#{bean.list2}" var="r" rows="#{userBean.tableRows}"
	paginator="true"  paginatorAlwaysVisible="false" 
	paginatorTemplate="{CurrentPageReport} | {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} | {RowsPerPageDropdown}"
	rowsPerPageTemplate="10,15,20,50,100"
	style="width: 100%;" styleClass="dt">

<p:column style="width:10px">  
	<p:rowToggler />  
</p:column>  
				
<p:column style="width:20px" sortBy="#{r.id}" parser="number">
	<f:facet name="header">  
		<h:outputText value="ID" />
	</f:facet>
        <h:outputText value="#{r.id}" />
</p:column>
				
	<ui:insert name="columns" />

<p:column style="width:20px">  
	<p:commandLink action="#{bean.read}" ajax="false">
		<h:graphicImage value="/images/edit.gif" />
		<f:setPropertyActionListener value="#{r}"
			target="#{bean.current}" />  
	</p:commandLink>
</p:column> 
...
Tested with primefaces 2.2-RC2 and primefaces 2.2 on JBoss AS6.
primefaces 3.0
Mojarra-2.1.4

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

10 Feb 2011, 15:46

Hi,

Funny, deja vu. We had the same issue with YUI based datatable in 2.0.2. After sorting / filtering I had to "refresh" client-side YUI widget (hack) in order to build right indexes. I didn't test it for new datatable, but if it's true, it would be a critical bug for us.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

10 Feb 2011, 17:41

Can you replicate it at showcase complex table sample, it has sorting and selection;

http://www.primefaces.org/showcase/ui/d ... omplex.jsf

3.1415926535
Posts: 7
Joined: 10 Feb 2011, 14:57

11 Feb 2011, 11:06

Ok, problem solved.

Fault was on my side. i had a filter over all rows which resets the list after submit, thats why i got the "unsorted value" everytime.
primefaces 3.0
Mojarra-2.1.4

prophet
Posts: 92
Joined: 17 Mar 2011, 19:59

28 Mar 2011, 14:29

I have the same probleme and i can't resolve it by myself. before sorting all data in my table display correct and when I click on command button test all data display correct in my dialog too and my button "disable" is disable in a right order when I select the row (when data in row is null)! But after sorting data in that table my dialog display old values (that were in my table before sorting) and my button "disable" is disable in the wrong places (in the places thats were right before sorting)! where i have made a mistake! Please help me!

Code: Select all

  <p:dataTable id="myTable" var="test" value="#{table.list}"
                         paginator="true" rows="10"
                         rowsPerPageTemplate="10,20,30"
                         paginatorTemplate="{FirstPageLink} {PreviousPageLink}
                         {PageLinks} {NextPageLink}
                         {LastPageLink} {RowsPerPageDropdown}"
                         dynamic="true" styleClass="panel"
                         emptyMessage="#{msg.emptyTableMessage}"
                         selection="#{table.selectedTest}" selectionMode="single"
                         onRowSelectUpdate="myTable:disable, myTable:test">           
                <p:column sortBy="#{test.id}">
                    <f:facet name="header">
                        ID
                    </f:facet>
                    <h:outputText value="#{test.id}" />
                </p:column>

                <p:column sortBy="#{test.word}" filterBy="#{test.word}">
                    <f:facet name="header">
                        Word
                    </f:facet>
                    <h:outputText value="#{test.word}"/>
                </p:column>

                <p:column filterBy="#{test.foo.name}">
                    <f:facet name="header">
                        Name
                    </f:facet>
                    <h:outputText value="#{test.foo.name}" />
                </p:column>

              <f:facet name="footer">
                             <p:commandButton id="disable" value="to do"  disabled="#{test.selectedTest.foo.name eq null}">       
                                       <f:setPropertyActionListener value="#{test}" target="#{table.selectedTest}" />      
                            </p:commandButton>
                             <p:commandButton value="test"   oncomplete="Dialog.show();">
                                       <f:setPropertyActionListener value="#{test}" target="#{table.selectedTest}" />      
                            </p:commandButton>
              </f:facet>
            </p:dataTable>


        <p:dialog header="Dialog" widgetVar="Dialog" resizable="true" showEffect="clip" hideEffect="fold" modal="true"  styleClass="panel">

                <h:outputText id="test" value="#{test.selectedTest.id}"/>   

        </p:dialog>


And I've noticed - when i apply my filter in any column and after that sort my data in any column, them all work fine (i can sort data many times and all display right)! I can't understand this behavior!

Alexandre
Posts: 16
Joined: 18 Jan 2011, 10:36

28 Mar 2011, 15:27

your dataTable Bean must implement Serialisable. and your bean must be in view scope.
Primefaces 2.2.1

prophet
Posts: 92
Joined: 17 Mar 2011, 19:59

28 Mar 2011, 15:51

Thank you! It works fine now!

User avatar
mediterran81
Posts: 29
Joined: 22 Mar 2011, 12:14
Location: France
Contact:

06 Apr 2011, 23:42

Please, tell us what you mean by the bean must be ine view scope!

PjOmcS
Posts: 7
Joined: 08 Jul 2016, 16:41

28 Jun 2018, 13:09

It means that your bean must be annotated with @ViewScoped and it lives exactly as long as a JSF view.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 43 guests