PF4 DataTable Cell Edit not udating/rendering correctly.

UI Components for JSF
Post Reply
ChrisGWarp
Posts: 12
Joined: 25 Mar 2014, 07:49

04 Apr 2014, 14:03

Hi All.

I have an issue with the Cell Edit mode of a data table.

I only have a single cell per row that needs to be able to be edited.

I can edit it. The changed value is not then displayed. Although, oddly enough, when I re-edit the same cell, the changed value is displayed again.

The onChange call is made to the server side bean, but the old and new values are both the same.

Basing the example similar to the showcase one, the growl message is not displayed.

This is the full xhtml code:

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<!-- jsf:pagecode language="java" location="/src/main/java/pagecode/ManageIniFile.java" --><!-- /jsf:pagecode -->
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	template="theme/ccd.xhtml">
	<ui:define name="body-content">
	
		<center>
			<h:form styleClass="form" id="form">

				<p:growl id="messages" showDetail="true"/>

				<h:panelGrid columns="1" cellpadding="20" width="50%">
					<h1 class="title ui-widget-header ui-corner-all">Manage Environments</h1>
						<div class="entry">

							<p:tabView id="tabView" var="section" value="#{iniFile.sections}">

								<p:tab id="sectionTab" title="#{section}">

									<p:dataTable var="entry" value="#{iniFile.getEntries(section)}" editable="true" editMode="cell">

										<p:ajax event="cellEdit" listener="#{pc_ManageIniFile.onCellEdit}" update=":form:messages" />

										<p:column headerText="Entry">
	            							<h:outputText value="#{entry.entry}" />
	        							</p:column>

										<p:column headerText="Value">
	            							<p:cellEditor>
	                   							<f:facet name="output"><h:outputText value="#{entry.value}" /></f:facet>
	                   							<f:facet name="input"><p:inputText value="#{entry.value}" style="width:46%" label="Value" /></f:facet>
	               							</p:cellEditor>
	        							</p:column>

	 								</p:dataTable>

								</p:tab>

							</p:tabView>
			
							<h:panelGrid columns="2" width="50%">
								<h:commandButton type="submit" value="Add Environment" styleClass="loginButton" id="addSection" />
								<h:commandButton type="submit" value="Save Environment" styleClass="loginButton" id="saveFile" />
							</h:panelGrid>

						</div>
				</h:panelGrid>
			</h:form>
		</center>

	</ui:define>
</ui:composition>
The pagecode bean, that has the onCellEdit() method is as follows:

Code: Select all

    public void onCellEdit(CellEditEvent event)
    {
        Object oldValue = event.getOldValue();
        Object newValue = event.getNewValue();

        System.out.println("oldValue=" + oldValue);
        System.out.println("newValue=" + newValue);

        if (newValue != null && !newValue.equals(oldValue))
        {
            FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Cell Changed", "Old: " + oldValue + ", New:" + newValue);
            FacesContext.getCurrentInstance().addMessage(null, msg);
        }
    }
Irrespective of what I'm editing, oldValue always equals newValue. :cry:

Can anyone who knows better than I offer any suggestions?

As once this page works, the app is pretty much done.

Thanks,

-Chris

ChrisGWarp
Posts: 12
Joined: 25 Mar 2014, 07:49

07 Apr 2014, 13:44

As a follow up, I can see the values being passed through to the server in the POST request.

I can also see the links to the growl being passed back in the response, but I am not seeing the growl either.

I am also getting some XHTML writer warnings server side about unclosed tags. I'm not sure if that's impacting this either.

This currently is running on Linux with WAS 8.5.0.2 which is using the IBM supplied build of MyFaces 2.0. Is that supported?

-Chris

ChrisGWarp
Posts: 12
Joined: 25 Mar 2014, 07:49

15 Apr 2014, 13:45

As a follow up.

I've upgraded from WAS 8.5.0.2 -> 8.5.5.1. It still has the MyFaces 2.0 impl in it.

That makes no difference.

I've also added in a new JSF impl, MyFaces 2.2.2. That too made no difference.

At least I've learned how to correctly set up and use a different JSF implementation. :)

I can see that the request does include the edited cell value in the request sent back to the server. The onCellEdit() method is being called, however, it is not able to extract the updated value correctly.

I've also updated PF 4 to 4.0.6-UR2, and that too makes no difference.

-Chris

ChrisGWarp
Posts: 12
Joined: 25 Mar 2014, 07:49

24 Apr 2014, 03:35

Getting the data model was part of the problem, the other was that I was led astray by the EL's ability to do a little more, in this case calling functions.

The original code was:

Code: Select all

<p:dataTable id="envEntries" var="entry" value="#{iniFile.getEntries(section)}" editable="true" editMode="cell" >
Whilst this rendered correctly, it was the cause of all of my onCellEdit() issues, as although the request map was correct (so I could have fudged it myself - but that was not the point) JSF could not find the values to allow the correct onCellEdit() operation.

The working code is:

Code: Select all

<p:dataTable id="envEntries" var="entry" value="#{iniFile.entries}" editable="true" editMode="cell">
So I had to maintain the data model in a manner that allowed it to work with JSF.

Once I did all of that, the app is working as expected. :D

-Chris

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 29 guests