简体   繁体   中英

Where is PrimeFaces cellEdit state maintained?

Does anyone know where/how PF maintains state for whether the input or output facet of ap:cellEditor was last shown? I want to be able to reset that state to gain better control of when PF thinks it needs to fire ap:dataTable's cellEdit event.

I ask because I have a screen with an editable p:dataTable (editMode="cell") where a user can trigger ap:remoteCommand while the input facet of ap:cellEditor is open, and that p:remoteCommand refreshes the screen such that all p:cellEditors go back to showing their output facets (this is correct behavior on the p:remoteCommand's part). The problem is that after the p:remoteCommand's refresh, PF seems to think that all p:cellEditors are still showing their input facet (even though they've gone back to showing their output facet), so whenever a user clicks a cell the p:dataTable's cellEdit is fired immediately such that the cell only briefly switches from its output facet to its input facet. Put another way, after the p:remoteCommand refreshes the screen, PF appears to think that any click on ap:cellEditor should trigger the p:dataTable's cellEdit event, so when the user clicks a cell they only see the input facet for the blink of an eye before the cellEdit event causes the cell to flip back to the output facet.

Any ideas on what JavaScript or Java code I could have my p:remoteCommand invoke to reset whatever PF is using to decide whether or not it is time to fire ap:dataTable's cellEdit event?

I'm using PF 5.1.13 with Wildfly 9.0.1.

For reference, here is the (sanitized) p:dataTable

<h:form id="form">
<p:outputPanel styleClass="tablesPanel" id="tablesPanel">
    <c:forEach var="table" items="#{view.tables}">             
        <p:dataTable id="table-#{table.tableIdSuffix}" widgetVar="tableWidget-#{table.tableIdSuffix}" value="#{table.rowAsList}" var="row" styleClass="compressed no-highlight" editable="#{view.allowEdit()}" editMode="cell">
                    <p:ajax event="cellEdit" listener="#{view.handleCellEdit}" oncomplete="onCellEdit()"/>
                    <p:columns value="#{table.row.cells}" var="cell">
                        <f:facet name="header">
                            <h:outputText value="#{cell.columnHeader}"/>
                        </f:facet>
                        <p:cellEditor>
                            <f:facet name="output">
                                <h:outputText rendered="#{view.allowEdit()}" styleClass="btn-link" value="#{cell.displayText}"/>
                                <h:outputText rendered="#{!view.allowEdit()}" value="#{cell.displayText}"/>
                            </f:facet>
                            <f:facet name="input">
                                <p:selectOneMenu id="selectedCellType-#{table.tableIdSuffix}-#{cell.id}" value="#{cell.valueTypeId}" style="width: 50px" >
                                    <f:selectItems value="#{view.valueTypes}" var="vt" itemLabel="#{vt.displayPrefix}" itemValue="#{vt.id}"/>
                                </p:selectOneMenu>
                                <p:inputText id="selectedCellValue-#{table.tableIdSuffix}-#{cell.id}" value="#{cell.value}" converter="#{bigDecimalConverter}" style="width: 40px;margin-bottom: 17px"/>
                                <p:selectOneMenu id="selectedCellUnit-#{table.tableIdSuffix}-#{cell.id}" value="#{cell.unitId}" style="width: 80px">
                                    <f:selectItems value="#{view.units}" var="u" itemLabel="#{u.displaySuffix}" itemValue="#{u.id}"/>
                                </p:selectOneMenu>
                            </f:facet>
                        </p:cellEditor>
                    </p:columns>
        </p:dataTable>
    </c:forEach>
</p:outputPanel>
</h:form>

And here's the (sanitized) remoteCommand that can be invoked while a cell's input facet is open

<h:form id="changeGroupForm" class="hide">
    <p:remoteCommand name="ajaxGroupUpdate" actionListener="#{view.refreshTables()}" update=":form:tablesPanel"/>
    <p:inputText id="groupId" value="#{view.groupId}"/>
</h:form>

For completeness, here also is the (sanitized) remoteCommand for the oncomplete attribute of the cellEdit event

<h:form>
    <p:remoteCommand name="onCellEdit" action="#{view.reportCellEdit()}" update=":form:tablesPanel"/>
</h:form>

I am just having exact same problem and the answer is:

<p:remoteCommand name="onCellEdit" update="tableId" oncomplete="PF('tableId').currentCell=null;"/>

But honestly I don't like because it seems hacky at best.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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