Pregunta

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, but the changed value is not then displayed. Although, oddly enough, when I re-edit the same cell, the changed value is displayed.

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:

<?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:

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

As a follow up, I've tried Mojarra 2.2.6 and MyFaces 2.2.2 with PF 4 and 5.0.RC1. The same result. I don't think that the cell editing works inside a tabView. I have managed to get the showcase example working, so I know that cell editing works on WAS 8.5.5.1 and MF 2.2.2.

¿Fue útil?

Solución

I was able to replicate the issue, caused by a javascript problem in PrimeFaces 4.0 CE when a validation error occured. I upgraded to use 4.0.6 UR2 (Unofficial Release) http://primefaces.github.io/

Source: https://github.com/primefaces/primefaces/tree/4.0.6-UR2 (build from source).

It seems the bug was fixed in an ELITE version, and fixed for PrimeFaces 5, and put into an unofficial release - I think it was fixed in 4.0.3 under this issue reported:

https://code.google.com/p/primefaces/issues/detail?id=6312

EDIT * After discussing with you and actually looking further into it - we established that its because your entries were trying to be dynamic but weren't stored as a variable on the scope of the page, so it had nothing to reference.

Cheers

Otros consejos

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 call functions.

The original code was:

<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:

<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.

-Chris

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top