简体   繁体   English

在cellEdit上消失p:DataTable p:ajax事件

[英]Disappearing p:DataTable on cellEdit p:ajax event

I use NetBeans 8.2, GlassFish 5.0, PrimeFaces 5.0. 我使用NetBeans 8.2,GlassFish 5.0,PrimeFaces 5.0。 I created a page with a cell editable data table. 我创建了一个带有单元格可编辑数据表的页面。 When I do the modification on one cell after the ajax event the whole data table replaced by the modified value. 当我在ajax事件之后对一个单元格进行修改时,整个数据表都被修改后的值所代替。 Just like the ajax respond does not send back the whole table contents. 就像ajax response不会发回整个表内容一样。 How can I correct it? 我该如何纠正?

The facelet: 方面:

    <h:form id="frmDemands">
        <p:growl id="msgs" showDetail="true"/>
        <div>
        <p:dataTable 
            id="dtblDemands" 
            value="#{demandUtility.demands}" 
            var="demand" 
            editable="true" 
            editMode="cell" 
            paginator="true" 
            paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
            rowsPerPageTemplate="5,10,15">
            <p:ajax event="cellEdit" listener="#{applicantBean.onCellEdit}" update=":frmDemands :frmDemands:msgs"/>
            <f:facet name="header">Demands</f:facet>
            <p:column headerText="ID">
                <h:outputText value="#{demand.id}"/>
            </p:column>
            <p:column headerText="Amount">
                <p:cellEditor>
                    <f:facet name="output"><h:outputText value="#{demand.amount}"/></f:facet>
                    <f:facet name="input"><p:inputText value="#{demand.amount}"/></f:facet>
                </p:cellEditor>
            </p:column>
            <p:column headerText="State">
                <h:outputText value="#{demand.state}"/>
            </p:column>
            <p:column>
                <p:commandButton value="Delete" rendered="#{applicantBean.isDemandDeleteable( demand )}" actionListener="#{applicantBean.onDeleteDemand( demand.id )}" update="@form"/>
            </p:column>
        </p:dataTable>
        </div>
    </h:form>

The backing bean handle the cellEdit event: 支持bean处理cellEdit事件:

@Named
@RequestScoped
@Data
public class ApplicantBean
{

  @Inject
  private DemandUtility demandUtility;

  ...

  public void onCellEdit( CellEditEvent event_ )
  {
    int rowIndex = event_.getRowIndex();
    double newValue = (Double) event_.getNewValue();
    Demand demand = demandUtility.getDemands().get( rowIndex );
    demand.setAmount( newValue );

    Event event = new Event( demandUtility.getNextEventId(), new Date(), "Demand (" + demand.getId() + ") modified! New amount: " + newValue );
    demandUtility.getEvents().add( event );
  }

  ...

}

When I try to set the @parent value to the update attribute of the ajax event the dataTable disappears as well. 当我尝试将@parent值设置为ajax事件的update属性时, dataTable消失了。

Can somebody help me, please? 有人可以帮我吗?

Create a which updates you table and change your Scope to @ViewScoped It worked for me. 创建一个更新表的表并将您的范围更改为@ViewScoped。

<h:form id="frmDemands">
    <p:growl id="msgs" showDetail="true"/>
    <p:remoteCommand name="rcCellEditUpdate" 
                     update=":frmDemands:dtblDemands :frmDemands:msgs" />
    <div>
        <p:dataTable 
            id="dtblDemands" 
            value="#{demandUtility.demands}" 
            var="demand" 
            editable="true" 
            editMode="cell" 
            paginator="true" 
            paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
            rowsPerPageTemplate="5,10,15">
            <p:ajax event="cellEdit" listener="#{applicantBean.onCellEdit}" oncomplete="rcCellEditUpdate();"/>
            <f:facet name="header">Demands</f:facet>
            <p:column headerText="ID">
                <h:outputText value="#{demand.id}"/>
            </p:column>
            <p:column headerText="Amount">
                <p:cellEditor>
                    <f:facet name="output"><h:outputText value="#{demand.amount}"/></f:facet>
                    <f:facet name="input"><p:inputText value="#{demand.amount}"/></f:facet>
                </p:cellEditor>
            </p:column>
            <p:column headerText="State">
                <h:outputText value="#{demand.state}"/>
            </p:column>
            <p:column>
                <p:commandButton value="Delete" rendered="#{applicantBean.isDemandDeleteable( demand )}" actionListener="#{applicantBean.onDeleteDemand( demand.id )}" update="@form"/>
            </p:column>
        </p:dataTable>
    </div>
</h:form>

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

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