无法将数据插入数据库

时间:2012-04-28 12:35:31

标签: hibernate primefaces

我无法使用Hibernate和postgres在我的数据库中执行INSERT。

<p:panel id="PanelAjoutDept" header="Ajouter département" style="width: 450px;height: 450px" >  
        <h:panelGrid id="GridAjoutDept" columns="2" cellpadding="20" >  
               <h:outputText value="Nom : " />  
               <p:inputText id="libelleDept1" value="#{departementBean.departement.libelleDepartement}" />

               <h:outputText value="Téléphone : " />  
               <p:inputText id="libelleDept2" value="#{departementBean.departement.telDepartement}" />

               <h:outputText value="Fax : " />  
               <p:inputText id="libelleDept3" value="#{departementBean.departement.faxDepartement}" />

               <h:outputText value="Responsable : " />  
               <p:inputText id="libelleDept4" value="#{departementBean.departement.respDepartement}" />

               <p:commandButton id="BoutonValideDept" value="Valider" action="#{departementBean.addDepartement()}"
                                                 update="PanelListeDept, ListDataTableDept"  ajax="true"/>

               <p:commandButton value="Reset" type="reset" />
       </h:panelGrid>  
</p:panel>

这就是Bean:

@ManagedBean(name = "departementBean")
@SessionScoped
public class DepartementBean implements Serializable {

    @ManagedProperty(value = "#{departementService}")
    private DepartementService departementService;
    private List<Departement> list;
    private Departement departement;
    private Departement departementTemp;
    private int length;
    private DepartementDataModel departementDataModel;

    public DepartementBean() {
        departement = new Departement();
        list = new ArrayList<Departement>();

    }

    @PostConstruct
    public void init() {
        list = new ArrayList<Departement>();
        list.addAll(departementService.findAll());
        length = list.size();
    }

    public void addDepartement() {
        System.out.println("///////////////////////Add:" + list.size() + "\n");
        if (departement == null) {
            departement = new Departement();
        }
        departementService.save(departement);
        list = departementService.findAll();
        System.out.println("///////////////////////Add:" + list.size() + "\n");
        length = list.size();
    }


//getter and setter

当我尝试点击Valide按钮时,我有这个错误:

  

javax.el.PropertyNotFoundException:/ Genseignant.xhtml @ 50,124   value =“#{departementBean.departement.libelleDepartement}”:目标   无法访问,'departement'返回null   com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100)     在   org.primefaces.renderkit.InputRenderer.getConverter(InputRenderer.java:162)     在   org.primefaces.renderkit.InputRenderer.getConvertedValue(InputRenderer.java:175)     at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1030)     在javax.faces.component.UIInput.validate(UIInput.java:960)at   javax.faces.component.UIInput.executeValidate(UIInput.java:1233)at at   javax.faces.component.UIInput.processValidators(UIInput.java:698)at at   javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)     在   javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)     在   org.primefaces.component.panel.Panel.processValidators(Panel.java:284)     在   javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)     在   javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)     在   org.primefaces.component.accordionpanel.AccordionPanel.processValidators(AccordionPanel.java:296)     在javax.faces.component.UIForm.processValidators(UIForm.java:253)     在   javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)     在   javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)     在   javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1172)     在   com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)     在com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)at   com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)     在javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)     在   org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:368)     在   org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)

请问有什么不对。

0 个答案:

没有答案