简体   繁体   English

Primefaces数据表单元格编辑不会更新

[英]Primefaces datatable cell editing doesn't update

I have a primefaces datatable with cell editing which is toggled on a boolean variable in the view. 我有一个带有单元格编辑的primefaces数据表,该表在视图中的布尔变量上切换。

I have three issues: 我有三个问题:

  1. In edit mode, I change a value and I click the save button on the page it doesn't keep the new value, If I click anywhere else first on the page then click save it will keep the value. 在编辑模式下,我更改了一个值,然后单击页面上的“保存”按钮,它不保留新值。如果我先单击页面上的其他任何地方,然后单击“保存”,它将保留该值。 I need it to keep the value if you click save first. 如果您先单击保存,则我需要它来保留值。
  2. If I edit a cell which is an input text and I click out the field now is a output text until I click in there again. 如果我编辑作为输入文本的单元格,然后单击该字段,则现在是输出文本,直到再次单击此处。 I want the field to look like a input text while in edit mode. 我希望字段在编辑模式下看起来像输入文本。
  3. When the save button is clicked the backing method sets the editable boolean to false, and the rest of the page obeys, and the dataTable looks like it obeyed but if you click a cell it will let you edit it. 单击“保存”按钮时,后备方法将可编辑的布尔值设置为false,其余页面遵循,而dataTable看起来也遵循它,但是如果单击单元格,它将允许您对其进行编辑。

Here is the code: 这是代码:

<p:dataTable value="#{view.LineItems}" var="lineItem" rowKey="#{lineItem.lineItemId}"
                 resizableColumns="false" editable="#{view.editable}" editMode="cell"
                 editingRow="#{view.editable}" id="requestLineItemsTable">

        <p:ajax event="cellEdit" listener="#{view.cellEdited}" immediate="true" update="@this" />

        <p:column styleClass="centerColumnData" headerText="Item Name" style="width: 140px;">
            <p:cellEditor>
                <f:facet name="output">
                    <h:outputText value="#{lineItem.title}"/>
                </f:facet>
                <f:facet name="input">
                    <h:inputText value="#{lineItem.title}"/>
                </f:facet>
            </p:cellEditor>
        </p:column> ...

and this is the back end (not doing anything with this yet) 这是后端(尚未对此进行任何操作)

public void cellEdited(CellEditEvent event)
{
    Object oldValue = event.getOldValue();
}

and here is the save and edit buttons on the same .xhtml page as datatable 这是与数据表相同的.xhtml页面上的保存和编辑按钮

 <p:commandLink process="@this"
                       action="#{view.changeModeToEdit}"
                       update="@form"
                       rendered="#{!view.editMode">
            <h:graphicImage library="images" name="edit20.png" title="#{__Common.edit}"
                            style="height: 15px; width: 15px;"/>
        </p:commandLink>
<components:linkWithSpinner linkStyle="margin-right: 20px;" loadingImageStyle="margin-right: 20px;"
                                    linkStyleClass="activeButton saveButtonRequestDetails" loadingImageStyleClass="saveButtonRequestDetails"
                                    linkText="#{__CommonButton.save}"
                                    process="@form" update="@form"
                                    actionMethod="#{view.updateRequest()}"/>

view.updateRequest() sets the editable to false. view.updateRequest()将editable设置为false。 I am using Primefaces 4.0 我正在使用Primefaces 4.0

So I figured out a way around these issues. 因此,我想出了解决这些问题的方法。 I was focused on using the built in edit table , but you can just have a normal datatable and the columns can contain input text fields. 我专注于使用内置的编辑表,但是您只能拥有一个普通的数据表,并且这些列可以包含输入文本字段。 Then you don't have to worry about most of the issues in my question above. 然后,您不必担心我上面的问题中的大多数问题。 If you need to switch between edit and non-edit view then I still don't know how to fully fix it except have two datatables in your file with render tags, but then you are duplicating the table one with input text fields and one with output text fields, and that is not the best way to do it. 如果您需要在编辑视图和非编辑视图之间切换,那么我仍然不知道如何完全解决它,除了文件中带有渲染标记的两个数据表外,然后您将复制带有输入文本字段的表和一个复制表。输出文本字段,这不是最好的方法。

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

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