我正在使用jsf 2.2并且我试图将所选值保存到我的数据库中,但我总是得到:Erreur转换值«1»pour«null转换器»。
我需要在需求的外键字段中插入医疗法的ID。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.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>
<title>Ajouter Demande</title>
</h:head>
<h:body>
<h:form id="form">
<p:panel header="Actes médicaux">
<p:messages id="messages" />
<p:tab title="Utilisateur">
<h:panelGrid id="grid1" columns="2" cellpadding="5" layout="grid"
styleClass="ui-panelgrid-blank">
<p:outputLabel for="console" value="Type de l'acte médical:" />
<p:selectOneMenu id="console" value="#{demandeBean.demande.actemedical}"
style="width:125px">
<f:selectItems value="#{acteMedicalBean.listacte}" var="acte" itemLabel="#{acte.typeActeMedical}"
itemValue="#{acte.idActeMedical}"
/>
</p:selectOneMenu>
<p:commandButton immediate="true" value="+">
</p:commandButton>
<p:commandButton update="form" value="Sauvegarder" id="button"
actionListener="#{demandeBean.save()}"
style="background:#6FDC6F;color: #FFFFFF;float:right"
styleClass="customStyleButton">
<p:confirm header="Confirmation" message="Êtes-vous sûr?"
icon="ui-icon-alert" />
<p:confirmDialog global="true" showEffect="fade" hideEffect="fade">
<p:commandButton value="Oui" type="button"
styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
<p:commandButton value="Non" type="button"
styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
</p:confirmDialog>
</p:commandButton>
</h:panelGrid>
</p:tab>
</p:panel>
</h:form>
</h:body>
</html>
package com.sopra_hr.GestionRemboursement.entities;
// default package
// Generated 5 avr. 2017 16:43:08 by Hibernate Tools 3.4.0.CR1
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
/**
* Demande generated by hbm2java
*/
@Entity
@Table(name = "DEMANDE", catalog = "ASSURANCE")
public class Demande implements java.io.Serializable {
private Integer idDemande;
private Actemedical actemedical;
private Utilisateur utilisateur;
private Demande demande;
private Double montantDemande;
private Date dateDemande;
private String etatDemande;
private Set<Demande> demandes = new HashSet<Demande>(0);
public Demande() { actemedical = new Actemedical();
}
public Demande(Actemedical actemedical, Utilisateur utilisateur, Demande demande, Double montantDemande,
Date dateDemande, String etatDemande, Set<Demande> demandes) {
this.actemedical = actemedical;
this.utilisateur = utilisateur;
this.demande = demande;
this.montantDemande = montantDemande;
this.dateDemande = dateDemande;
this.etatDemande = etatDemande;
this.demandes = demandes;
}
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "ID_DEMANDE", unique = true, nullable = false)
public Integer getIdDemande() {
return this.idDemande;
}
public void setIdDemande(Integer idDemande) {
this.idDemande = idDemande;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "FK_ID_ACTE_MEDICAL")
public Actemedical getActemedical() {
return this.actemedical;
}
public void setActemedical(Actemedical actemedical) {
this.actemedical = actemedical;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "FK_MATRICULE_UTILISATEUR")
public Utilisateur getUtilisateur() {
return this.utilisateur;
}
public void setUtilisateur(Utilisateur utilisateur) {
this.utilisateur = utilisateur;
}
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "FK_ID_ACTE_MEDICAL", insertable = false, updatable = false)
public Demande getDemande() {
return this.demande;
}
public void setDemande(Demande demande) {
this.demande = demande;
}
@Column(name = "MONTANT_DEMANDE", precision = 17, scale = 0)
public Double getMontantDemande() {
return this.montantDemande;
}
public void setMontantDemande(Double montantDemande) {
this.montantDemande = montantDemande;
}
@Temporal(TemporalType.DATE)
@Column(name = "DATE_DEMANDE", length = 8)
public Date getDateDemande() {
return this.dateDemande;
}
public void setDateDemande(Date dateDemande) {
this.dateDemande = dateDemande;
}
@Column(name = "ETAT_DEMANDE", length = 100)
public String getEtatDemande() {
return this.etatDemande;
}
public void setEtatDemande(String etatDemande) {
this.etatDemande = etatDemande;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "actemedical")
public Set<Demande> getDemandes() {
return this.demandes;
}
public void setDemandes(Set<Demande> demandes) {
this.demandes = demandes;
}
}
package com.sopra_hr.GestionRemboursement.beans;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import org.apache.log4j.Logger;
import com.sopra_hr.GestionRemboursement.entities.Actemedical;
import com.sopra_hr.GestionRemboursement.entities.Demande;
import com.sopra_hr.GestionRemboursement.services.ActemedicalService;
import com.sopra_hr.GestionRemboursement.services.DemandeService;
import com.sopra_hr.GestionRemboursement.services.imp.ActemedicalServiceImp;
import com.sopra_hr.GestionRemboursement.services.imp.DemandeServiceImp;
@ManagedBean
@ViewScoped
public class DemandeBean implements Serializable{
public static Logger log = Logger.getLogger(DemandeBean.class);
private Demande demande = new Demande();
private Actemedical acte = new Actemedical();
private DemandeService demandeService = new DemandeServiceImp();
private ActemedicalService acteService = new ActemedicalServiceImp();
private List<Demande> listdemandes = new ArrayList<Demande>();
private List<Actemedical> listactes = new ArrayList<Actemedical>();
@PostConstruct
public void init(){
try {
listdemandes =demandeService.findAll();
listactes =acteService.findAll();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void save() {
try {
demandeService.save(demande);
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "", "Demande ajouté avec succes"));
} catch (Exception e) {
FacesContext.getCurrentInstance().addMessage(null,
new FacesMessage(FacesMessage.SEVERITY_ERROR, "", "Erreur d'insertion"));
e.printStackTrace();
}
}
public Demande getDemande() {
return demande;
}
public void setDemande(Demande demande) {
this.demande = demande;
}
public Actemedical getActe() {
return acte;
}
public void setActe(Actemedical acte) {
this.acte = acte;
}
public DemandeService getDemandeService() {
return demandeService;
}
public void setDemandeService(DemandeService demandeService) {
this.demandeService = demandeService;
}
public List<Demande> getListdemandes() {
return listdemandes;
}
public void setListdemandes(List<Demande> listdemandes) {
this.listdemandes = listdemandes;
}
public List<Actemedical> getListactes() {
return listactes;
}
public void setListactes(List<Actemedical> listactes) {
this.listactes = listactes;
}
}