将数据从对话框添加到datable-jsf-primefaces

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将数据从对话框添加到datable-jsf-primefaces相关的知识,希望对你有一定的参考价值。

我遇到了从对话框向我的数据表添加数据的问题。我单击命令按钮“添加”,应出现一个对话框,然后保存数据条目,但是当我检查它们时,我发现它们为空(数据表单行选择)。

代码:

<p:commandButton process="singleDT" update=":form:add" icon="ui-icon-plus" value="Add"
    oncomplete="PF('addDialog').show()" />

<p:dataTable id="singleDT" var="o" value="#UserBean.listE" selectionMode="single"
    selection="#UserBean.selectedEvent" rowKey="#o.id_event">
    <p:column headerText="Id">
        <h:outputText value="#o.id_event" />
    </p:column>
    <p:column headerText="Event">
        <h:outputText value="#o.event" />
    </p:column>
    <p:column headerText="Date">
        <h:outputText value="#o.date_event" />
    </p:column>
</p:dataTable>

单击按钮“添加”时的对话框:

 <p:dialog header="Addevent" widgetVar="addDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false">
    <p:outputPanel id="ajouter" style="text-align:center;">

        <p:panelGrid  columns="2"  columnClasses="label,value">
         <h:outputText value="Id:" />
            <h:inputText value="#id_event" />

            <h:outputText value="Event" />
            <h:inputText value="#event" />

            <h:outputText value="Date " />
            <h:inputText value="#date_event" />
        </p:panelGrid>
       </p:outputPanel>
    <p:commandButton action="#UserBean.Add" icon="ui-icon-edit" value="Add"  />

UserBean方法Add()

public void Add()

    System.out.println("adding");
    event e=new event();
    e.setId_event(id_event);
    e.setEvent(event);
    e.setDate_event(date_event);
    serviceevent.add(e);
    System.out.println("added to database ");
    listE= serviceevent.findAll();
    System.out.println("refrech ");

堆栈错误:

Hibernate: insert into event (date_event, etat_event, event) values (?, ?, ?)
juin 29, 2017 10:43:46 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 1048, SQLState: 23000
juin 29, 2017 10:43:46 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Le champ 'event' ne peut être vide (null)
juin 29, 2017 10:43:46 PM com.sun.faces.lifecycle.InvokeApplicationPhase execute
AVERTISSEMENT: #UserBean.Ajouter: org.hibernate.exception.ConstraintViolationException: could not execute statement
javax.faces.FacesException: #UserBean.Ajouter: org.hibernate.exception.ConstraintViolationException: could not execute statement
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
    at javax.faces.component.UICommand.broadcast(UICommand.java:315)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:958)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:452)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1087)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)
Caused by: javax.faces.el.EvaluationException: org.hibernate.exception.ConstraintViolationException: could not execute statement
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
    ... 27 more
Caused by: org.hibernate.exception.ConstraintViolationException: could not execute statement
    at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:59)
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97)
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:208)
    at org.hibernate.dialect.identity.GetGeneratedKeysDelegate.executeAndExtract(GetGeneratedKeysDelegate.java:57)
    at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:42)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2909)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3480)
    at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:81)
    at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:623)
    at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:277)
    at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:258)
    at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:303)
    at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:318)
    at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:275)
    at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:182)
    at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:113)
    at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:192)
    at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:38)
    at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:177)
    at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:32)
    at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:73)
    at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:682)
    at org.hibernate.internal.SessionImpl.save(SessionImpl.java:674)
    at org.hibernate.internal.SessionImpl.save(SessionImpl.java:669)
    at com.ismo.gestionabsence.dao.eventDAOImpl.add(eventDAOImpl.java:19)
    at com.ismo.gestionabsence.services.eventservicesImpl.add(eventservicesImpl.java:19)
    at com.ismo.gestionabsence.presentation.UserBean.Ajouter(UserBean.java:331)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.el.parser.AstValue.invoke(AstValue.java:279)
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:273)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
    ... 28 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Le champ 'event' ne peut être vide (null)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
    at com.mysql.jdbc.Util.getInstance(Util.java:408)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:935)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3973)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3909)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2527)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2680)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2501)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1858)
    at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2079)
    at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2013)
    at com.mysql.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.java:5104)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1998)
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:205)
    ... 60 more

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9PS2V0Ti5wbmcifQ==” alt =“对话框的图像”>。

我想念什么?

答案

根据例外,页面无法处理'selectedEvent',因为它是null

另一答案

好,答案很简单,我没有喝足够的水,它是jsf的基础知识(愚蠢的帖子:)>

   <!-- dialog addevent -->
    <p:dialog header="Add event" widgetVar="addDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false">
    <p:outputPanel id="add" style="text-align:center;">

        <p:panelGrid  columns="2"  columnClasses="label,value">
         <h:outputText value="Id:" />
            <h:inputText value="#UserBean.id_event" />

            <h:outputText value="Event" />
            <h:inputText value="#UserBean.event" />

            <h:outputText value="Date " />
            <h:inputText value="#UserBean.date_event" />
        </p:panelGrid>
       </p:outputPanel>
    <p:commandButton action="#UserBean.Add" icon="ui-icon-edit" value="Save"  />
    <p:commandButton process="singleDT" update=":form:add" icon="ui-icon-
</p:dialog>

以上是关于将数据从对话框添加到datable-jsf-primefaces的主要内容,如果未能解决你的问题,请参考以下文章

如何从列表视图按钮单击将多个数据添加到数组列表?

从 AlertDialog 输入将项目添加到 RecyclerView

Android 将 Activity 添加到带有 Intent 的对话框

从片段类中的对话框添加项目到recyclerview。

vc++6.0如何实现在模态对话框编辑框中输入数据,单击确定按钮将数据添加到组合框按钮中!

如何将数据从片段传递到对话框片段