0

i use JSF 2.0 and primefaces 4.0

my JSF code :

 <c:forEach items="#{materielbean.materielist}" var="list" >
        <p:dataTable  var="car" value="#{materielbean.listeitemsmaterielbyidmateriel(list.idmateriel)}" rowKey="#{car.iditemsmateriel}"  
                 selection="#{fournisseurbean.selectedItemsMateriel}" selectionMode="multiple" style="width : 664px; ">  
        <f:facet name="header">  
          #{list.nommateriel} 
        </f:facet>          


        <p:column headerText="designation">  
            #{car.designation}  
        </p:column>  
        <p:column headerText="Unité">  
            #{car.unite}  
        </p:column>   


    </p:dataTable> 

     </c:forEach> 

and the used function

listeitemsmaterielbyidmateriel(list.idmateriel)

is defined like this

public List listeitemsmaterielbyidmateriel(int i){
return  itemmaterielDAO.DisplayItemsMaterielDAOselonmMateriel(i);
}

And finally this is the DAO code

public  List DisplayItemsMaterielDAOselonmMateriel(int idmateriel )
    {

        Query q = em.createQuery("select LIM from ItemsMateriel LIM inner join LIM.materiel where LIM.materiel.idmateriel= :idmateriel");
        q.setParameter("idmateriel", idmateriel);
        List l = new ArrayList();
        l= q.getResultList();

        return l ;
    }

when i run this code , i got no errors , but selection="#fournisseurbean.selectedItemsMateriel}" returns only the values of the final iteration(final datatable) , it's because in every iteration the list crashes old selected objects and put new selected objects , how can i do to prevent this ??

Bellil Med Samouel
  • 321
  • 2
  • 8
  • 20
  • It is a known issue, but it was fixed recently for MyFaces 2.2.x. See: [MYFACES-3811](https://issues.apache.org/jira/browse/MYFACES-3811) for details. You could try if the [latest snapshot](https://repository.apache.org/content/repositories/snapshots/org/apache/myfaces/core/) and see if it works for you. – lu4242 Nov 29 '13 at 00:47

2 Answers2

2

It's dangerous to mix JSTL core tags with JSF- and/or *Faces tags. Basically JSTL tag handler get executed during view build time, while JSF UIComponents get executed during view render time. See the very good answer at "JSTL in JSF2 Facelets… makes sense?"

Have you already tried to solve the issue using Facelets ui:repeat component?

Community
  • 1
  • 1
L-Ray
  • 1,637
  • 1
  • 16
  • 29
1

Well sorry for late , but i discovored that the solution is easier than i thought : First create a new list

List<ItemsMateriel> Tampon = new ArrayList<ItemsMateriel>();

Second modify the setter to :

public void setSelectedItemsMateriel(List<ItemsMateriel> selectedItemsMateriel) {               
        Tampon.addAll(selectedItemsMateriel);
        this.selectedItemsMateriel = selectedItemsMateriel;         
    }

And finally to use the new list (Tampon) and you'll find all selected objects

Bellil Med Samouel
  • 321
  • 2
  • 8
  • 20