原始数据datatable ejb更新返回旧数据 [英] primefaces rowediting datatable ejb update returns old data

查看:144
本文介绍了原始数据datatable ejb更新返回旧数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



Iam使用标点3.4,glassfish 3.1,jsf2.0和ejb 3.我试图实现标准展示datatable划线。但是当我将更新的值验证到datatable中时,我会获得旧的值。这是我的代码:

 < h:form id =form> 
< p:growl id =messagesshowDetail =true/>
< p:dataTable var =itemvalue =#{jSFMBean.allContacts}id =contactListeditable =true>
< p:ajax event =rowEditlistener =#{jSFMBean.onEdit}update =@ this:form:messages/>
< p:ajax event =rowEditCancellistener =#{jSFMBean.onCancel}update =:form:messages/>
< p:column headerText =EMAILstyle =width:125px>
< p:cellEditor>
< f:facet name =output>
< h:outputText value =#{item.email}/>
< / f:facet>
< f:facet name =input>
< p:inputText value =#{item.email}label =EMAIL/>
< / f:facet>
< / p:cellEditor>
< / p:column>< p:column headerText =Optionsstyle =width:50px>
< p:rowEditor />
< / p:column>
< / p:dataTable>
< h:outputText value =#{jSFMBean.selectedContact.displayname}/>



方法是: public void onEdit(RowEditEvent event){
this.session.updateContact((Contacts)event.getObject()); p>

  FacesMessage msg = new FacesMessage(版本联系人:,((Contacts)event.getObject())。getDisplayname()); 

FacesContext.getCurrentInstance()。addMessage(null,msg);
}

(Contacts)event.getObject()得到旧的值:(这就像在ajax更新到数据库之前首先发送数据的消息。



我做错什么我感谢你的帮助解决这个。

解决方案

似乎每当你需要你的dataTable,你从数据库中获取它,这就是为什么event.getObject()总是返回旧值,所以在你的datatable的getter中你需要添加:

  if(allContacts == null){ 

allContacts =(List< Contacts>)yourservice.getAll(); / *这是指从数据库获取列表的函数* /

}

返回allContacts;

我希望可以帮助你。


Salut :), iam a newbie in primefaces and ajax

Iam using primefaces 3.4, glassfish 3.1, jsf2.0 and ejb 3. I tried to implement primefaces showcase datatable rowediting. But when i validate the updated value into the datatable, i get the old value. This is my code :

<h:form id="form">
<p:growl id="messages" showDetail="true"/>
<p:dataTable var="item" value="#{jSFMBean.allContacts}" id="contactList" editable="true">
    <p:ajax event="rowEdit" listener="#{jSFMBean.onEdit}" update="@this :form:messages" />
    <p:ajax event="rowEditCancel" listener="#{jSFMBean.onCancel}" update=":form:messages" />
        <p:column headerText="EMAIL" style="width:125px">
                    <p:cellEditor>
                        <f:facet name="output">
                            <h:outputText value="#{item.email}" />
                        </f:facet>
                        <f:facet name="input">
                            <p:inputText value="#{item.email}" label="EMAIL"/>
                        </f:facet>
                    </p:cellEditor>
                </p:column><p:column headerText="Options" style="width:50px"> 
                    <p:rowEditor />
                </p:column>
     </p:dataTable>
<h:outputText value="#{jSFMBean.selectedContact.displayname}" />

the methods are :

  public void onEdit(RowEditEvent event) {
    this.session.updateContact((Contacts) event.getObject());
    FacesMessage msg = new FacesMessage("Edition contact: ", ((Contacts) event.getObject()).getDisplayname());

    FacesContext.getCurrentInstance().addMessage(null, msg);
}

(Contacts) event.getObject() always get the old value :(. It's like the getter of the datatable fireup first before ajax update to the database.

what iam i doing wrong ? thank you for your help solving this .

解决方案

It seems that whenever you need your dataTable you are getting it from your database and that's why event.getObject() always returns the old value.So in the getter of your datatable you need to add:

if (allContacts== null){

        allContacts= (List<Contacts>) yourservice.getAll();  /*this refers to the function that get the list from the database*/

    }

    return allContacts;

I hope that may help you.

这篇关于原始数据datatable ejb更新返回旧数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆