PrimeFaces DataTable RowEditor在RowEditInit上更新单元格元素,但不在RowEdit或RowEditCancel上更新 [英] PrimeFaces DataTable RowEditor updating cell elements on RowEditInit, but not on RowEdit or RowEditCancel

查看:239
本文介绍了PrimeFaces DataTable RowEditor在RowEditInit上更新单元格元素,但不在RowEdit或RowEditCancel上更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下xhtml:

<h:form>
...
<p:dataTable id="table" value="#{BEAN.rows} var="row" >
    <p:ajax event="rowEdit" listener="#{BEAN.rowEdit}" />
    <p:ajax event="rowEditInit" listener="#{BEAN.rowEditInit}" />
    <p:ajax event="rowEditCancel" listener="#{BEAN.rowEditCancel}" />
    ...
    <p:columns id="columnsElement"
        value="#{BEAN.columns} var="column" >
        <f:facet name="header" >
            <h:outputText value="#{column.code}" />
            <p:selectBooleanCheckbox id="selectAll"
                disabled="#{BEAN.rowInEdit}" />
        </f:facet>

        <p:cellEditor>
            <f:facet name="output">
                <p:selectBooleanCheckbox id="cellCheck"
                    disabled="#{BEAN.rowInEdit} />
            </f:facet>
            <f:facet name="input">
                <p:selectBooleanCheckbox id="selectAll"
                disabled="true" />
            </f:facet>
        </p:cellEditor>
    </p:columns>
</p:dataTable> </h:form>

使用RowEdit侦听器如下:

With the RowEdit listeners as follows:

public void rowEditInit(RowEditEvent event) {
rowInEdit = true;
UIData table = (UIData) event.getComponent();
String tableId = table.getClientId();
updateTableCheckboxes(tableId, table.getRowIndex());     }

public void rowEdit(RowEditEvent event) {
rowInEdit = false;
UIData table = (UIData) event.getComponent();
String tableId = table.getClientId();
updateTableCheckboxes(tableId, table.getRowIndex());    } // same for rowEditCancel

public void updateTableCheckboxes(String tableId, int index) {
int rowNumber = 0;
for (RowData row : rows) {
    int columnNumber = 0;
    for (ColumnData column : columns) {
        if (row != index) {
            String updateCheckboxId = tableId + ":" + rowNumber
                + ":columnsElement:" + columnNumber + ":cellCheck";
            FacesContext.getCurrentInstance()
                .getPartialViewContext().getRenderIds()
                .add(updateCheckboxId);
        }
        columnNumber++;
    }
    rowNumber++;
}

columnNumber = 0;
while (columnNumber < columns.size()) {
    String selectAllCheckboxId = tableId + ":columnsElement:"
        + columnNumber + ":selectAll";
    FacesContext.getCurrentInstance().getPartialViewContext()
        .getRenderIds().add(selectAllCheckboxId);
    columnNumber++;
}}

这将动态填充<$ c $中复选框的ID c> columnsElement 进行更新,并且对于 rowEditInit 正常工作,可以按预期禁用所有复选框。当我单击 rowEdit rowEditCancel 事件的刻度/十字时,要更新的ID完全相同,

This is dynamically populating the Ids of the check boxes in columnsElement to be updated and is working fine for rowEditInit, disabling all checkboxes as expected. When I click the tick/cross for the rowEdit or rowEditCancel event the Ids to be updated are populated exactly the same, but only the check boxes of the row which had been edited are re-enabled.

如果我单击屏幕其他位置的组件或重新启用的一项检查,则仅重新启用已编辑的行的复选框。框,然后选中其他行的复选框,然后奇怪地重新启用了selectAll复选框。

If I click on a component elsewhere on the screen or one of the re-enabled check boxes then check boxes of other rows and the selectAll check boxes are all re-enabled as well strangely.

我已经尝试像此博客,但是生命周期的所有阶段对于Init,Edit和Cancel的调用都完全相同。

I have tried debugging the JSF lifecycle phases as in this blog, but all stages of the lifecycle are called exactly the same for Init, Edit and Cancel.

据我所知,我正在做相同的事情,但是在不同情况下得到不同的结果。

As far as I can see I'm doing the same thing, but getting different results in the different cases. Any suggestions why this could be happening?

谢谢

推荐答案

I设法在数据表之外使用< p:remoteCommand /> 来解决此问题,如下所示...

I've managed to fix this using <p:remoteCommand/> outside of the datatable as follows...

< p:remoteCommand name = updateDataTable update = table />

并添加 oncomplete = updateDataTable() rowEdit rowEditCancel ajax事件。

and adding oncomplete="updateDataTable()" to the rowEdit and rowEditCancel ajax events.

这给了我想要的最终结果,但是我仍然很好奇为什么最初的解决方案不起作用,或者是否有更好的解决方案。

This has given me the desired end result, but I am still curious why my initial solution didn't work or if there's a better solution.

这篇关于PrimeFaces DataTable RowEditor在RowEditInit上更新单元格元素,但不在RowEdit或RowEditCancel上更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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