Erreur "java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Number"
Bonjour tous;
J'ai une erreur qui apparait lors de developpement d'une application j2ee, j'utilise jpa et jsf.L'erreur apparait lors de l'ajourt(action ajouter) ," java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Number". voici les codes xhtml et le bean:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| <?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:composite="http://java.sun.com/jsf/composite">
<head>
</head>
<body>
<h2> INFORMATIONS DEPARTEMENT </h2>
<hr /><hr />
<h:form>
<h:panelGrid columns="2" cellpadding="2" >
NOM : <h:inputText value ="#{deprtBean.dep.nomdepart}"/>
<br /> <br />
<h:commandButton value="Ajouter" action="#{deprtBean.ajouter }"/>
</h:panelGrid>
</h:form>
</body>
</html> |
le bean correspondant 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
|
package com.xx.personne.controlleur;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import com.xx.personne.dao.deprtdao;
import com.xx.personne.persistence.deprt;
@ManagedBean
@SessionScoped
public class deprtBean {
private deprt dep=new deprt();
deprtdao depdao=new deprtdao();
public deprtBean() {
// TODO Auto-generated constructor stub
}
public deprt getDep() {
return dep;
}
public void setDep(deprt dep) {
this.dep = dep;
}
/***************************/
public String ajouter(){
depdao.ajouter(dep);
return null;
}
} |
Le dao :
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 63 64 65 66 67 68 69 70 71 72 73 74
|
package com.xx.personne.dao;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Persistence;
import com.xx.personne.persistence.deprt;
public class deprtdao {
private deprt dep=new deprt();
private EntityManager ed;
public deprtdao() {
// TODO Auto-generated constructor stub
}
public deprt getDep() {
return dep;
}
public void setDep(deprt dep) {
this.dep = dep;
}
public EntityManager getEd() {
if(ed==null)
ed=Persistence.createEntityManagerFactory("Personne").createEntityManager();
return ed;
}
public void ajouter(deprt dep){
getEd().getTransaction().begin();
getEd().persist(dep);
getEd().getTransaction().commit();
}
public void modifier(deprt dep) {
// TODO Auto-generated method stub
getEd().getTransaction().begin();
getEd().merge(dep);
getEd().getTransaction().commit();
}
public void supprimer(deprt dep) {
// TODO Auto-generated method stub
getEd().getTransaction().begin();
getEd().remove(dep);
getEd().getTransaction().commit();
}
public List<deprt> selectAll(){
try {
@SuppressWarnings("unchecked")
List<deprt> resultList = getEd().createQuery("select dep from deprt dep").getResultList();
return resultList;
} catch (Exception e) {
return null;
// TODO: handle exception
}
}
public deprt selectBynom(String nomdepr){
try {
deprt resultList = (deprt) getEd().createQuery("select dep from deprt dep where dep.nom=:pp").setParameter("pp", nomdepr).getSingleResult();
return resultList;
} catch (Exception e) {
return null;
// TODO: handle exception
}
}
} |
Je ne sais pas ou il se realise le cast exactement!! :calim2:
merci pour votre aide