salut;
j'ai une erreur lors de l'insertion a une table person; l'insertion doit se faire aprés le remplissage des champs nom prenom et un choix d'une entreprise a partir d'un combobox.
Person.hbm.xml:
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 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com.cynapsys.business.businessobject"> <class name="Person" table="Person" lazy="false"> <id name="id" column="id_person" type="java.lang.Integer"> <generator class="sequence"> <param name="sequence">SEQ_PERSON</param> </generator> </id> <property name="firstName" column="firstname" type="java.lang.String"> </property> <property name="lastName" column="lastname" type="java.lang.String"> </property> <many-to-one name="entreprise" class="Entreprise" not-null="true"> <column name="id_entreprise"></column> </many-to-one> </class> </hibernate-mapping>
Entreprise.hbm.xml
la methode de remplissage du combobox
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 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com.cynapsys.business.businessobject"> <class name="Entreprise" table="Entreprise" lazy="false"> <id name="id" column="id_entreprise" type="java.lang.Integer"> <generator class="sequence"> <param name="sequence">SEQ_ENTREPRISE</param> </generator> </id> <property name="name" column="name" type="java.lang.String"> </property> <set name="person" inverse="true"> <key column="id_entreprise"/> <one-to-many class="Person" /> </set> </class> </hibernate-mapping>
la page addperson.jsp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 public List<SelectItem> getListEntreprises() { List<Entreprise> list = (List<Entreprise>) this.getEntreprises(); List<SelectItem> listEnter = new ArrayList<SelectItem>(); for(int index=0; index<list.size();index++) { listEnter.add(new SelectItem(list.get(index).getId(),list.get(index).getName())); } listEntreprises = listEnter; return listEntreprises; }
le pb qu"il n'affiche aucune erreur et lors de l'apuit sur le bouton il n'y aura pas aucune insertion
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 <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%><%@taglib uri="http://richfaces.org/a4j" prefix="a4j"%> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%> <html> <head> <title>Add Person</title> </head> <body> <f:view> <form id="AddPersonForm"> <h:panelGrid border="1" columns="2"> <h:outputText value="First Name:"></h:outputText> <h:inputText value="#{personBean.person.firstName}"></h:inputText> <h:outputText value="Last Name:"></h:outputText> <h:inputText value="#{personBean.person.lastName}"></h:inputText> <h:selectOneMenu value="#{personBean.person.entreprise}" > <f:selectItems value="#{entrepriseBean.listEntreprises}"/> </h:selectOneMenu> <h:commandButton value="submit" action="#{personBean.addPersonAction}"></h:commandButton> </h:panelGrid> </form> </f:view> </body> </html>![]()
Partager