Bonjour,
J'ai une page ajout.xhtml qui contient deux champs nom et prénom et un bouton enregistrer,quand je clique sur enregistrer je veux ue les données de la personne soient enregistrées dans la base de données ,quand je clique il n'ya rien ,c'est un PFE et je suis bloquée :( voici mon code
//ajout.xhtml :
<!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:ui="
https://www.oracle.com/java/technologies/ "
xmlns:h="
https://www.oracle.com/java/technologies/ "
xmlns:f="
https://www.oracle.com/java/technologies/ "
xmlns:p="http://primefaces.prime.com.tr/ui">
<h:head>
<link href="style.css" rel="stylesheet" type="text.css"/>
</h:head>
<h:body>
<p>
<h:outputText value="Last Name" />
<h:inputText value="#{PersonBean.per.lastName}" />
</p>
<p>
<h:outputText value="First Name" />
<h:inputText value="#{PersonBean.per.firstName}" />
</p>
<h:commandButton value="Save" action="#{PersonBean.SavePerson}" />
</h:body>
</html>
//PersonBean:
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import com.util.Person;
import java.util.List;
@ManagedBean(name="PersonBean")
@SessionScoped
public class PersonBean {
PersonDao perdao;
Person per;
List<Person> perList;
public PersonBean() {
perdao = new PersonDao();
}
public Person getPer()
{return per;}
public void setPer(Person per)
{this.per=per;}
public String SavePerson(){
perdao.savepersonne(per);
return "rose";
}
}
//PersonDao:
import org.hibernate.Session;
import com.util.HibernateUtil;
public class PersonDao {
Session session = null;
public PersonDao(){
this.session = HibernateUtil.getSessionFactory().getCurrentSession();
}
public void savepersonne(com.util.Person per) {
org.hibernate.Transaction tx =session.beginTransaction();
per.setId(per.getId());
per.setFirstName(per.getFirstName());
per.setLastName(per.getLastName());
session.save(per);
tx.commit();
session.close();
}
}
//Person :
package com.util;
public class Person implements java.io.Serializable {
private static final long serialVersionUID = 1L;
private Integer id;
private String lastName;
private String firstName;
public Person() {
}
public Person(String lastName, String firstName) {
this.lastName = lastName;
this.firstName = firstName;
}
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
public String getLastName() {
return this.lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getFirstName() {
return this.firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
}
//hibernate.cfg.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"
http://hibernate.org/dtd/hibernate-configuration-3.0.dtd ">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="current_session_context_class">thread</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="hibernate.show_sql">true</property>
<mapping resource="com/util/Person.hbm.xml" />
</session-factory>
</hibernate-configuration>
Afficher la suite