0

I'm working on a datatable with a single selection mode.My problem is that when I refesh the page , the same selected rows before refreshing stay refreshed. Any idea on how unselecting all datatable rows in this case. I appreciate helping me with this issue.

This is my datatable code:

    <p:dataTable id="cars1" var="car"   widgetVar="carsTable" value="#{typePrimeManager.tprimes}" editable="false" style="margin-bottom:20px"  paginator="false"  selectionMode="single" selection="#{typePrimeManager.selectedtype}" rowKey="#{car.idPrime}">
    <p:ajax event="rowSelect" update=":form:cars2" />
    <p:ajax event="rowUnselect" listener="#{typePrimeManager.setSelectedtype(null)}" update=":form:cars2"/>
    <p:ajax event="rowUnselect" listener="#{typePrimeManager.setSelectedtype(null)}" update=":form:cars2"/>
    <p:column headerText="intitule des types">  
    <h:outputText value="#{car.intitulePrime}" />
    </p:column>
    </p:dataTable>
Saad
  • 21
  • 1
  • 2
  • 4
  • You use a managed bean with SessionScoped ? This keep the value unchange. For cleaning the selected row when the page is refresh you need to reset selectedtype too. – Joffrey Hernandez May 18 '15 at 10:54
  • that's true, I am using a Scope("session"). but how can I reset the selected type? – Saad May 18 '15 at 11:00
  • I recommand to you to read this : https://stackoverflow.com/questions/7031885/how-to-choose-the-right-bean-scope If you want to keep using SessionScope and reset the selectedrow you have to clean the selectedtype inside your bean – Joffrey Hernandez May 18 '15 at 11:02
  • You're welcome. Think to validate the answer and Welcome on stackoverflow :) – Joffrey Hernandez May 18 '15 at 11:47

2 Answers2

0

You use a managed bean with SessionScoped ? This keep the value unchange. I Recommand to you to read this : How to choose the right bean scope?

If you want to keep using SessionScope and reset the selected rows you have to clean the selectedtype inside your bean

Joffrey Hernandez
  • 1,809
  • 3
  • 21
  • 39
0

If you have to have a session scoped bean, you need to clear the value that DataTable holds to reference the selected item which in your case is typePrimeManager.selectedtype.

So if you set this value to null or any object of the same type that is not in the DataTable dataSource than your problem will resolved, but you have to do this before page is reloaded. To get that event you can use pre-defined JSF events ,like PreRenderView, to execute a method in which you should clear the selected value, or you can define a remoteCommand that will call the appropriate bean method and execute that remoteCommand with javascript when the page is loaded.

YamYamm
  • 381
  • 1
  • 3
  • 12