How to update dataTable after AJAX event cellEdit?

UI Components for JSF
Post Reply
natrajn
Posts: 12
Joined: 24 May 2014, 08:13

05 Sep 2014, 03:36

Hi

I have a simple requirement that someone else ought to have had before, but cannot find a solution in the forums.

I have a datatable with in editMode="cell", in which only the first column editable. When the cell is edited and loses focus, the AJAX event gets fired properly. The logic in that backing bean method changes rest of the data for that row, based on the input. At this point I want to show the updated data in that row. But no matter what I have tried, it does not show the updated data in the row/table. (I can verify that the data has indeed changed in the list by switching to another screen and coming back to it).

I tried partialSubmit="true", process="@this", forcing update of the individual cells using RequestContext, updating the entire datatable with and without an enclosing form etc. - none works. In each case, I am making sure that I am referring to the appropriate ID generated in the pattern ":formID:componentID". I also made sure that there are no JavaScript errors on the page.

Relevant JSF code:

Code: Select all

            <h:form id="badSsnForm"> 

                <p:dataTable id="badSsnsList" value="#{ssnXRefMBean.ssnXRefInfo.badSsnTEs}"
                             var="item" rowKey="item.ssn" editable="true" editMode="cell">
                    <p:ajax event="cellEdit" listener="#{ssnXRefMBean.onCellEdit}" update=":badSsnForm:badSsnsList,:growlMsg"/>

                    <f:facet name="header">
                        <h:outputText value="Bad SSNs"/>
                    </f:facet>

                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="SSN"/>
                        </f:facet>
                        <p:cellEditor>
                            <f:facet name="output">
                                <h:outputText value="#{item.ssn}" />
                            </f:facet>
                            <f:facet name="input">
                                <p:inputMask id="itemSsn" value="#{item.ssn}" mask="999-99-9999" converter="SsnConverter"
                                             title="Please enter 9 digits" size="12" autocomplete="off" />
                            </f:facet>
                        </p:cellEditor>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="TE SUID"/>
                        </f:facet>
                        <h:outputText id="teSuid" value="#{item.teSuid}"/>
                    </p:column>
                    <p:column >
                        <f:facet name="header">
                            <h:outputText value="Name"/>
                        </f:facet>
                        <p:outputLabel id="dispName" value="#{item.displayName}"/>
                    </p:column>
<!-- other columns -->
                 </p:dataTable>

            </h:form> 


cellEdit event handler in the backing bean:

Code: Select all

    public void onCellEdit(CellEditEvent event) {
        int index = event.getRowIndex();
        String oldSsn = (String) event.getOldValue();
        String newSsn = (String) event.getNewValue();

// Other logic to get the info for newSsn from the EJB
        ssnXRefInfo.getBadSsnTEs().set(index, updatedTE);

        // Tried to update individual cells with the following, that also doesn't work
    //    RequestContext requestContext = RequestContext.getCurrentInstance();
    //    requestContext.update("badSsnForm:badSsnsList:" + index + ":teSuid");
    //    requestContext.update("badSsnForm:badSsnsList:" + index + ":dispName");
    }
Please help. Any way to show the updated data in the table, in the true AJAX way (without the user having to click another button).

Thanks
NN
NN

PrimeFaces version: 5.0.4 (Elite)
JSF 2.1 bundled with NetBeans 8.0
Weblogic server 12c (12.1.1.0) on Windows 7
Chrome (current), IE 10.

User avatar
andyba
Expert Member
Posts: 2473
Joined: 31 Mar 2011, 16:27
Location: Steinfeld, near Bremen/Osnabrück, DE
Contact:

05 Sep 2014, 11:58

The only thing I can think of is that you are changing the persisted values successfully but not refreshing the data used in the view.
PF 4.x (Elite versions), PF 5, Pf 5.1, PF 6.0
Glassfish 4.1, Mojarra 2.x, Java 8, Payara 4.1.1.
If you haven't read the forum rules read them now

natrajn
Posts: 12
Joined: 24 May 2014, 08:13

05 Sep 2014, 22:24

Andyba, Thanks for the quick response. But there is no persistence happening at that time - just a query to get the person data for the newly entered SSN.

This statement sets it to the list used by the dataTable:

Code: Select all

ssnXRefInfo.getBadSsnTEs().set(index, updatedTE);
As I mentioned, I can verify that the data has indeed changed in the list (ssnXRefMBean.ssnXRefInfo.badSsnTEs) by switching to another screen and coming back to it, in which case it is just displaying the updated data in the session (no query gets executed again unless I press a button).

Further, if I change the Ajax statement to update the entire form - like,

Code: Select all

       
<h:form id="badSsnForm">              
         <p:dataTable id="badSsnsList" value="#{ssnXRefMBean.ssnXRefInfo.badSsnTEs}"
                             var="item" rowKey="item.ssn" editable="true" editMode="cell">
                    <p:ajax event="cellEdit" listener="#{ssnXRefMBean.onCellEdit}" update=":badSsnForm,:growlMsg"/>
after the Ajax update kicks in, the entire dataTable disappears and only the entered value shows up in its place!

- NN
NN

PrimeFaces version: 5.0.4 (Elite)
JSF 2.1 bundled with NetBeans 8.0
Weblogic server 12c (12.1.1.0) on Windows 7
Chrome (current), IE 10.

evanp
Posts: 1
Joined: 01 Sep 2014, 09:22

22 Sep 2014, 11:40

Mybe you can try the following way if you don't hava a solution.

<p:ajax event="cellEdit" listener="#{ssnXRefMBean.onCellEdit}" update="@none"/>


public void onCellEdit(CellEditEvent event) {
int index = event.getRowIndex();
String oldSsn = (String) event.getOldValue();
String newSsn = (String) event.getNewValue();

// Other logic to get the info for newSsn from the EJB
ssnXRefInfo.getBadSsnTEs().set(index, updatedTE);

// Tried to update individual cells with the following, that also doesn't work
RequestContext requestContext = RequestContext.getCurrentInstance();
requestContext.update("badSsnForm:badSsnsList:" + index + ":teSuid");
requestContext.update("badSsnForm:badSsnsList:" + index + ":dispName");

requestContext.update("growlMsg");
}

LeoLozes
Posts: 1
Joined: 09 Jul 2015, 10:47

09 Jul 2015, 10:50

natrajn wrote: after the Ajax update kicks in, the entire dataTable disappears and only the entered value shows up in its place!
Hi Natranj, I have the exact same behaviour trying to update my datatable after a cellEdit ajax event (with Primefaces 5.2).

The strange thing is that other datatables update just fine. This one is dynamically generated in a c:forEach though, and I can't get the datatable to refresh correctly.

Did you find any solution?

petr.nadeiko
Posts: 2
Joined: 09 Sep 2015, 11:55

09 Sep 2015, 12:02

Hello!

Try this:

Code: Select all

		<p:remoteCommand name="onCellEdit"  update=":mainForm:mainTabView:plannedSupplyEditTable" />
		<p:dataTable emptyMessage="Brak danych" var="plannedSupply" id="plannedSupplyEditTable"
			value="#{tradeGoodsPlanningBean.plannedSupplies.rows}" 
			scrollable="true"
			scrollWidth="98%"
			editable="true"
			editMode="cell"
			rowStyleClass="#{plannedSupply.summaryRow ? 'suppliesSummary' : null}">
			
			<p:ajax event="cellEdit" listener="#{tradeGoodsPlanningBean.onCellEdit}" 
				oncomplete="onCellEdit()" />

Swapfaces
Posts: 13
Joined: 07 Oct 2019, 14:58

30 Jan 2023, 15:36

petr.nadeiko wrote:
09 Sep 2015, 12:02
Hello!

Try this:

Code: Select all

		<p:remoteCommand name="onCellEdit"  update=":mainForm:mainTabView:plannedSupplyEditTable" />
		<p:dataTable emptyMessage="Brak danych" var="plannedSupply" id="plannedSupplyEditTable"
			value="#{tradeGoodsPlanningBean.plannedSupplies.rows}" 
			scrollable="true"
			scrollWidth="98%"
			editable="true"
			editMode="cell"
			rowStyleClass="#{plannedSupply.summaryRow ? 'suppliesSummary' : null}">
			
			<p:ajax event="cellEdit" listener="#{tradeGoodsPlanningBean.onCellEdit}" 
				oncomplete="onCellEdit()" />
Hello from 2023 :) It helped me, thanks!
Primefaces 10, manhattan theme
TomCat version: 9.0.39
Faces API: javax.faces, javax.faces-api, 2.2
Faces implementation: com.sun.faces, jsf-impl, 2.2.8

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 23 guests