Access aux attributs du bean
salut tous le monde,
je suis en cours de raliser une fonction recherche a partir de deux champs je veux avoir une liste identique au deux champs la partie XHTM est
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>test</title>
</h:head>
<body>
<form>
<h:panelGrid columns="5">
<p:outputLabel for="site1" value="Site1 :"/>
<h:inputText id="site1" value="#{g2RtransController.nositea}" />
<p:outputLabel for="site2" value="Site2 :" />
<h:inputText id="site2" value="#{g2RtransController.nositeb}" />
<h:commandButton id="recherche" action="#{g2RtransController.liaisonAb()}" immediate="fals"/>
</h:panelGrid>
</form>
<h:dataTable value="#{g2RtransController.site}" var="a" >
<h:column >
<h:outputText value="#{a.nositea}" />
</h:column>
<h:column >
<h:outputText value="#{a.nositeb}" />
</h:column>
<h:column >
<h:outputText value="#{a.debit}" />
</h:column>
</h:dataTable>
</body>
</html> |
le controller :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| partie controller:
package Controller;
import java.io.Serializable;
import EJB.liaisonEJB;
import JPA.G2rtrans;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean
@SessionScoped
public class G2RtransController implements Serializable{
private String nositea;
private String nositeb;
private List<G2rtrans> site;
@EJB
private liaisonEJB transEJB;
public String getNositea() {
return nositea;
}
public void setNositea(String nositea) {
this.nositea = nositea;
}
public String getNositeb() {
return nositeb;
}
public void setNositeb(String nositeb) {
this.nositeb = nositeb;
}
public G2RtransController() {
}
public List<G2rtrans> getSite() {
return site;
}
public void setSite(List<G2rtrans> site) {
this.site = site;
}
public List<G2rtrans> listtransAll(){
return transEJB.listerliens();
}
public void liaisonAb(){
System.out.println(nositea);
site=transEJB.listerliensAB(nositea, nositeb);
}
} |
et l'EJB:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| partie EJB
package EJB;
import JPA.G2rtrans;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
/**
*
* @author Dridi Achref
*/
@Stateless
public class liaisonEJB {
@PersistenceContext(unitName = "G2RPU")
private EntityManager em;
public List<G2rtrans> listerliens(){
Query q=em.createNamedQuery("G2rtrans.findAll");
return q.getResultList();
}
public List<G2rtrans> listerliensAB(String nositea,String nositeb){
Query q=em.createNamedQuery("SELECT g FROM G2rtrans g WHERE g.nositea = :nositea AND g.nositeb = :nositeb").setParameter("nositea", nositea).setParameter("nositea", nositeb);
return (List<G2rtrans>) q.getResultList();
}
} |
merci d'avance :D