Primefaces中的单元格编辑不会更新值 [英] Cell edit in primefaces is not updating the value

查看:97
本文介绍了Primefaces中的单元格编辑不会更新值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的primefaces应用程序中有一个数据表.前端代码具有

I have a datatable in my primefaces application . The code for the frontend has

    <!-- Start of customer datatable -->
            <p:dataTable var="customer" value="#{customerBean.customers}" paginator="true" selection="#{customerBean.selectedCustomer}" 
            selectionMode="single" onRowSelectUpdate=":custList" onRowSelectComplete="custTab.show()" id="custList" widgetVar="custList" update=":custList">
                <f:facet name="header">
                List of Customers
                    <p:outputPanel>
                        <p:commandButton value="+" type="button" onclick="addCustDlg.show()"/>
                     </p:outputPanel>
                </f:facet>


                <p:column sortBy="#{customer.id}" filterBy="#{customer.id}" update=":custList">
                    <f:facet name="header">
                        <h:outputText value="ID"/>
                    </f:facet>
                    <h:outputText value="#{customer.id}"/>
                </p:column>

                <p:column sortBy="#{customer.name}" filterBy="#{customer.name}" headerText="NAME" filterMatchMode="contains" update=":custList">
                  <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{customer.name}"/>
                    </f:facet>
                    <f:facet name="input">
                        <p:inputText value="#{customer.name}"/>
                    </f:facet>
                  </p:cellEditor>
                </p:column>

                <p:column sortBy="#{customer.description}" filterBy="#{customer.description}" headerText="DESCRIPTION">
                  <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{customer.description}"/>
                    </f:facet>
                    <f:facet name="input">
                        <p:inputText value="#{customer.description}"/>
                    </f:facet>
                  </p:cellEditor>
                </p:column>

                <p:column sortBy="#{customer.signupDate}" filterBy="#{customer.signupDate}" headerText="SIGN UP DATE">
                    <f:facet name="output">
                        <h:outputText value="#{customer.signupDate}"/>
                    </f:facet>
                </p:column>

                <p:column sortBy="#{customer.validUntil}" filterBy="#{customer.validUntil}" headerText="EXPIRY DATE">
                  <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{customer.validUntil}"/>
                    </f:facet>
                    <f:facet name="input">
                        <p:inputText value="#{customer.validUntil}"/>
                    </f:facet>
                  </p:cellEditor>
                </p:column>

                <p:column sortBy="#{customer.status}" filterBy="#{customer.status}" headerText="STATUS">
                  <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{customer.status}"/>
                    </f:facet>
                    <f:facet name="input">
                        <p:inputText value="#{customer.status}"/>
                    </f:facet>
                  </p:cellEditor>
                </p:column>

                <p:column headerText="CREATION DATE" sortBy="#{customer.creationDate}" filterBy="#{customer.creationDate}">
                    <f:facet name="output">
                        <h:outputText value="#{customer.creationDate}"/>
                    </f:facet>
                </p:column>

                <p:column headerText="LAST UPDATE DATE" sortBy="#{customer.lastUpdateDate}" filterBy="#{customer.lastUpdateDate}">
                    <f:facet name="output">
                        <h:outputText value="#{customer.lastUpdateDate}"/>
                    </f:facet>
                </p:column>

                <p:column headerText="Options">
                    <p:rowEditor/>
                </p:column>

            </p:dataTable>
            <!-- End of dataTable (customer datatable) -->

并且在bean中将用于处理rowEvent的函数指定为

And the function for handling the rowEvent is specified in the bean as

 public void custRowEdit(RowEditEvent event){
    Customer cust = (Customer) event.getObject();
    EntityManagerHelper.beginTransaction();
    custDao.update(cust);
    EntityManagerHelper.commit();
}

但是,在更新事件中,当我编辑表中的单元格时,没有获得该属性的新更新值.

However , on an update event , when I am editing the cell in the table , I do not get the new updated value of the attribute .

就像下面的图片一样,当我将ID 1的条目的状态从11修改为4时,在函数custRowEdit中,当我尝试获取客户对象时,我仍然获得客户的状态11和不是4.

Like in the image below , when I edit the status of the entry with ID 1 from 11 to 4 , in the function custRowEdit , when I try to get the customer object , I still get the status of the customer as 11 and not 4 .

有人可以帮助我理解为什么未设置单元格的值吗?

Can anyone help me with understanding why the value of the cell is not being set ?

推荐答案

这对我有所帮助.

我可以补充一点,如果没有@构造函数托管的bean,则可以从构造函数中的查询中加载列表,而可以使用reset()方法将列表重置为null,然后从查询中懒惰地填充列表. .然后可以使用f:event在页面加载时调用重置:

May I add that instead of loading the list from a query in the constructor, if one has a @SessionScoped managed bean one can instead use a reset() method to reset lists to null and then lazily populate the lists from the query. The reset can then be called on page load using an f:event:

    <f:view>
        <f:metadata>
            <f:event type="preRenderView" listener="#{sessionScopedBean.reset}"/>
        </f:metadata>
    </f:view>        

这篇关于Primefaces中的单元格编辑不会更新值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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