Bonsoir;
J'ai un petit code jsf avec le quel je veux insérer des données facture dans une base de données.Le probleme c'est que dasn la base je ne trouve que "null ".
Voici le code xhtml et le bean
facture.xhtml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
 
</h:head>
<h:body>
<h2> FACTURE </h2>
<hr /><hr />
<h:form>
    <br />
     		<h:panelGrid columns="2">
FOURNISSEUR: <h:selectOneMenu value="#{factu.nomf}">
       <f:selectItems value="#{factu.listElements}" />
            </h:selectOneMenu>
                 		</h:panelGrid> 
        <br />  
 REFERENCE : <h:inputText  value ="#{factu.reference}"/>
                  <br /> <br />       
DATE: <p:calendar  value="#{factu.date}" showOn="both"/>
     	    <br />
 		<h:panelGrid columns="4">
 PRODUIT : <h:selectOneMenu value="#{factu.prodnom}">
       <f:selectItems value="#{factu.listElementsprod}" />
            </h:selectOneMenu>
                  <br />
 QUANTITE : <h:inputText  value ="#{factu.lcd.quantite}"/>
       <br />
TOTAL : <h:inputText  value ="#{factu.lcd.total}"/>
     		</h:panelGrid> 
      <br />
  <h:commandButton value="+" action="#{factu.add }"/>
        <br /><hr align="left"/>
  <h:commandButton value="Ajouter" action="#{factu.ajouter }"/>
 
</h:form> 
</h:body>
</html>
et son bean est
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
package com.xxx.facturation.controlleur;
 
import java.util.ArrayList;
import java.util.List;
 
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.SelectItem;
 
import java.util.Date;
 
 
 
import com.xxx.facturation.dao.FactureDAO;
import com.xxx.facturation.dao.FournisseurDAO;
import com.xxx.facturation.dao.ProduitDAO;
import com.xxx.facturation.persistance.Facture;
import com.xxx.facturation.persistance.Fournisseur;
import com.xxx.facturation.persistance.Lignecomd;
import com.xxx.facturation.persistance.Produit;
 
 
@ManagedBean(name="factu")
@SessionScoped
public class FactureBean {
	  private String nomf;
	  private String prodnom;
      private Date date;
      private float total;
  	  private String reference;
 
	private Fournisseur fs=new Fournisseur();
	private Produit pr=new Produit();
	private Facture fac = new  Facture();
	private Lignecomd lcd=new Lignecomd();
	  FactureDAO factdao= new FactureDAO();
	  FournisseurDAO frndao= new FournisseurDAO(); 
	  ProduitDAO pdao=new ProduitDAO();
 
	/***********************************************************/
	  private List<Fournisseur> listfs = new ArrayList<Fournisseur>();
	  private List<SelectItem> listElements;
	  private List<Produit> prdt= new ArrayList<Produit>();
	  private List<SelectItem> listElementsprod;
	  private List<Lignecomd> listlcde= new ArrayList<Lignecomd>();
 
	/***********************************************************/
 
	public FactureBean() {
 
		// TODO Auto-generated constructor stub
	}
 
	public Fournisseur getFs() {
		return fs;
	}
	public void setFs(Fournisseur fs) {
		this.fs = fs;
	}
	public Produit getPr() {
		return pr;
	}
	public void setPr(Produit pr) {
		this.pr = pr;
	}
	public List<Fournisseur> getListfs() {
		return listfs;
	}
	public void setListfs(List<Fournisseur> listfs) {
		this.listfs = listfs;
	}
 
	public List<SelectItem> getListElements() {
		listElements=new ArrayList<SelectItem>();
		for(Fournisseur fs:frndao.selectAll())
			listElements.add(new SelectItem(fs.getPrenom()));
		return listElements;
	}
 
	public void setListElements(List<SelectItem> listElements) {
		this.listElements = listElements;
	}
	public List<Produit> getPrdt() {
		return prdt;
	}
	public void setPrdt(List<Produit> prdt) {
		this.prdt = prdt;
	}
	public List<SelectItem> getListElementsprod() {
		 listElementsprod=new ArrayList<SelectItem>();
		for(Produit pr:pdao.selectAll())
			 listElementsprod.add(new SelectItem(pr.getNom()));
		return listElementsprod;
	}
 
	public void setListElementsprod(List<SelectItem> listElementsprod) {
		this.listElementsprod = listElementsprod;
	}
	public Facture getFac() {
		return fac;
	}
	public void setFac(Facture fac) {
		this.fac = fac;
	}
	  public String ajouter(){
		fs=frndao.selectBynom(nomf);
		fac.setFs(fs);
		pr=pdao.selectBynom(prodnom);	 
 
     lcd.setP(pr);
     listlcde.add(lcd);
     fac.setListlcde(listlcde);
 
    // fac.setReference(reference);
    // fac.setTotal(total);
     factdao.ajouter(fac);
          return null;
 
}
	  public String getProdnom() {
		  	return prodnom;
		  }
		  public void setProdnom(String prodnom) {
		  	this.prodnom = prodnom;
		  }
		  public String getNomf() {
		  	return nomf;
		  }
		  public void setNomf(String nomf) {
		  	this.nomf = nomf;
		  }  
 
	  public String add(){
 
/*****************    Selection Produit      ************************/
        pr=pdao.selectBynom(prodnom);
	      prdt.add(pr);
       prodnom=new String();
/*****************   Selection Fournisseur       ************************/
    	fs=frndao.selectBynom(nomf);
    	listfs.add(fs);
    	nomf=new String();
   return null;
	  }
 
	public Date getDate() {
		return date;
	}
 
	public void setDate(Date date) {
		this.date = date;
	}
 
	public Lignecomd getLcd() {
		return lcd;
	}
 
	public void setLcd(Lignecomd lcd) {
		this.lcd = lcd;
	}
    public float getTotal() {
		return total;
	}
 
	public void setTotal(float total) {
		this.total = total;
	}
 
	public String getReference() {
		return reference;
	}
 
	public void setReference(String reference) {
		this.reference = reference;
	}
 
	public List<Lignecomd> getListlcde() {
		return listlcde;
	}
 
	public void setListlcde(List<Lignecomd> listlcde) {
		this.listlcde = listlcde;
	}
 
	  }
Merci pour votre aide