简体   繁体   English

JSF- Primefaces 5.0 Roweditor无法识别新值

[英]JSF- Primefaces 5.0 roweditor does not recognize the new value

I'm trying to use the roweditor of PrimeFaces datatable and I have the problem that changing the value in the datatable the managed bean does not recognize the new value and the old remains. 我正在尝试使用PrimeFaces数据表的roweditor,但我遇到的问题是,更改托管bean的数据表中的值无法识别新值,而旧值仍然存在。

I almost "cloned" the showcase of RowEditing and surprisingly not work me. 我几乎“克隆”了RowEditing的展示柜,但令人惊讶的是,我无法正常工作。 I searched more posts and some say it may be a bug, but I replicated exactly the showcase example and it works. 我搜索了更多帖子,有人说这可能是错误,但我完全复制了展示示例,并且可以正常工作。 My version is PrimeFaces 5.0. 我的版本是PrimeFaces 5.0。

*.xhtml * .xhtml

<h:form id="frmExclos">
   <p:growl id="mensajeGeneral3" sticky="false" showDetail="true"/>
   <p:panel id="pnlCriteriExclusio" style="width: 425px" header="Criteris d'exclusió del pacient" widgetVar="pnlCriterisE">
   <p:dataTable id="tblCriterisExclusioNia" var="itemCriterisExclusio" value="#{mbRCriteriExclusio.getCriterisExclusioNia(mbVMalignitatNia.personaAmbMalignitatNia.id)}" editable="true">
     <p:ajax event="rowEdit" listener="#{mbRCriteriExclusio.onRowEdit}" update=":frmExclos:mensajeGeneral3" />
     <p:ajax event="rowEditCancel" listener="#{mbRCriteriExclusio.onRowCancel}" update=":frmExclos:mensajeGeneral3"  />
             <p:column headerText="Observacions">
               <p:cellEditor>
                  <f:facet name="output"><h:outputText value="#{itemCriterisExclusio.comentaris}"></h:outputText></f:facet>
                  <f:facet name="input"><p:inputText value="#{itemCriterisExclusio.comentaris}" label="Observacions"></p:inputText></f:facet>
               </p:cellEditor>
             </p:column>
             <p:column style="width:32px">
               <p:rowEditor />
             </p:column>
             <f:facet name="footer" ><p:commandButton update="@this" icon="ui-icon-plusthick" value="Afegir criteri" oncomplete="PF('dlgAddCriterisExclusio').show()"/>
              </f:facet>
       </p:dataTable>
       </p:panel>
</h:form> 

Then, the fragment of the managed bean MbRCriteriExclusio.java : 然后,托管bean MbRCriteriExclusio.java的片段:

@Named(value = "mbRCriteriExclusio")
@ViewScoped
public class MbRCriteriExclusio {
public void onRowCancel(RowEditEvent event) {
    FacesMessage msg = new FacesMessage("Edit Cancelled", "" + ((MalignitatPersonaCriterisExclusioNia) event.getObject()).getComentaris());
    FacesContext.getCurrentInstance().addMessage(null, msg);
}

In the Msg getComentaris returns the initial value loaded in the datatable not the new value that I've edited! 在消息中,getComentaris返回数据表中加载的初始值,而不是我编辑过的新值! The code of the showcase is the same .. 展示柜的代码是一样的..

thank you very much for your help 非常感谢您的帮助

In case of rowCancel, it wont reflect the new value since you are cancelling out the changes. 对于rowCancel,由于您要取消更改, 因此它不会反映新值 in this function public void onRowEdit(RowEditEvent event) you will be able to get modified value. 在此函数public void onRowEdit(RowEditEvent event)中,您将能够获取修改后的值。 Try this. 尝试这个。

In RowEditEvent same thing happens. 在RowEditEvent中,会发生同样的事情。

I did not write the function so that not too long the message 我没有写函数,所以消息不要太长

The msg shows me the initial value and not the updated in the RowEditEvent. 信息会向我显示初始值,而不显示RowEditEvent中的更新值。

Assuming the intended method is similar to: 假设预期方法类似于:

public void onRowEdit(RowEditEvent event) {
    Object o = event.getObject();
    persist(o);
}

Credit for the fix goes to: http://jwsn.blogspot.com/2013/05/issue-with-rowedit-event-in-primefaces.html 该修复的功劳在于: http : //jwsn.blogspot.com/2013/05/issue-with-rowedit-event-in-primefaces.html

If your datatable data model is backed by a getter with a query to the database, you may have to put a null check around the database call so that it only refreshes values when null. 如果您的数据表数据模型由带有查询数据库的getter支持,则您可能必须在数据库调用周围放置一个null检查,以便它仅在null时刷新值。 This was overwriting my "new" value at event.getObject() to the "old" value. 这会将event.getObject()的“新”值覆盖为“旧”值。

Guessing your getter is like this: 猜测您的吸气剂是这样的:

listOfX List<X>;

public List<X> getCriterisExclusioNia(idType id) {
    listOfX = getFacade().getListofX(id);
    return listOfX;
}

Make it like this: 使它像这样:

public List<X> getCriterisExclusioNia(idType id) {
    if(listOfX == null) {
        listOfX = getFacade().getListofX(id);
    }
    return listOfX;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM