Bonjour,

Je suis débutant sur Seam et j'essaye de faire fonctionner ce code pour ajouter un produit dans la bd :

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
 
package coursjsf;
 
import javax.ejb.Init;
import javax.persistence.Entity;
import javax.persistence.Id;
 
import org.hibernate.validator.Length;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
 
/**
 * Entité produit, qui dans un cas réel serait une entité persistante dans la base de données.
 */
@Entity
@Name("produit")
@Scope(ScopeType.SESSION)
public class Produit {
 
	@Id
	@Length(max=10)
	private String code;
 
	@Length(max=100)
	private String libelle;
 
	@Length(max=5000)
	private String description;
 
 
	Produit() {
	}
 
	/**
         * Crée un produit, avec un code servant d'identifiant, un libellé court et une description plus détaillé.
         * @param code
         * @param libelle
         * @param description
         */
	public Produit(String code, String libelle, String description) {
		this.code = code;
		this.libelle = libelle;
		this.description = description;
	}
 
 
	/**
         * Renvoie le code du produit, qui sert d'identifiant. Chaque produit a un code différent.
         * @return le code du produit.
         */
	public String getCode() {
		return code;
	}
 
	/**
         * Renvoie le libellé du produit.
         * @return le libellé du produit.
         */
	public String getLibelle() {
		return libelle;
	}
 
	/**
         * Renvoie la description détaillée du produit, qui est au format HTML.
         * @return la description du produit.
         */
	public String getDescription() {
		return description;
	}
 
}
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
 
package coursjsf;
import javax.ejb.Remove;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
 
import org.hibernate.validator.Valid;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.JndiName;
import org.jboss.seam.annotations.Name;
 
@Stateless
@Name("addManagerProduit")
@JndiName("addManagerProduit")
public class AddActionProduit {
 
	@PersistenceContext
	private EntityManager em;
 
	@Valid 
	@In
	private Produit produit;
 
	public void addProduit()
	{
		em.persist(produit);	
	}
 
	@Remove
	public void remove ()
	{
 
	}
}
JSF :

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
 
<!DOCTYPE composition 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:s="http://jboss.com/products/seam/taglib"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:c="http://java.sun.com/jstl/core"
	xmlns:io="http://www.iocean.fr/iotags">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="css/site.css" rel="stylesheet" type="text/css" />
<title>TP JSF/Seam</title>
</head>
 
<body>
<h:form>
	<h:inputText id="username" value="#{produit.libelle}" />
	<h:commandButton value="Valider" action="#{addManagerProduit.addProduit}" />
</h:form>
</body>
</html>
Une exception survient :

Avez-vous une idée ?

Merci