【问题标题】:JSF- Primefaces 5.0 roweditor does not recognize the new valueJSF-Primefaces 5.0 roweditor 无法识别新值
【发布时间】:2015-01-10 08:47:38
【问题描述】:

我正在尝试使用 PrimeFaces 数据表的行编辑器,但我遇到的问题是更改数据表中的值托管 bean 无法识别新值并且旧值仍然存在。

我几乎“克隆”了 RowEditing 的展示柜,但令人惊讶的是它对我不起作用。我搜索了更多帖子,有人说这可能是一个错误,但我完全复制了展示示例并且它有效。我的版本是 PrimeFaces 5.0。

*.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> 

然后,托管 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);
}

在消息中,getComentaris 返回加载到数据表中的初始值,而不是我编辑的新值! 陈列柜的代码是一样的..

非常感谢您的帮助

【问题讨论】:

    标签: jsf-2 primefaces datatable roweditor


    【解决方案1】:

    在 rowCancel 的情况下,它不会反映新值,因为您正在取消更改。 在这个函数 public void onRowEdit(RowEditEvent event) 你将能够得到修改后的值。 试试这个。

    【讨论】:

      【解决方案2】:

      在 RowEditEvent 中也会发生同样的事情。

      我没有写函数所以消息不会太长

      消息显示的是初始值,而不是 RowEditEvent 中的更新值。

      【讨论】:

        【解决方案3】:

        假设预期的方法类似于:

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

        修复的功劳归于:http://jwsn.blogspot.com/2013/05/issue-with-rowedit-event-in-primefaces.html

        如果您的数据表数据模型由带有数据库查询的 getter 支持,您可能必须对数据库调用进行空检查,以便它仅在为空时刷新值。这是将 event.getObject() 中的“新”值覆盖为“旧”值。

        猜你的getter是这样的:

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

        把它变成这样:

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

        【讨论】:

          猜你喜欢
          • 2013-05-08
          • 1970-01-01
          • 2014-09-14
          • 2012-05-28
          • 2013-12-20
          • 2012-08-23
          • 2011-12-14
          • 2016-03-01
          • 1970-01-01
          相关资源
          最近更新 更多