0

I have been banging my head trying to figure this out all morning and cannot get it to work. Basically, I cannot get a new dataTable value from a cellEdit event via PrimeFaces.

Here is my XHTML page:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
            xmlns:ui="http://java.sun.com/jsf/facelets" 
            xmlns:p="http://primefaces.org/ui"
            xmlns:h="http://java.sun.com/jsf/html"
            xmlns:f="http://java.sun.com/jsf/core">

<h:form id="httpPolicyForm">
    <p:dataTable id="httpTable" var="row" value="#{httpPolicyBean.rows}" editable="true" editMode="cell">
        <f:facet name="header">
            HTTP Policy
        </f:facet>
        <p:ajax event="cellEdit" listener="#{httpPolicyBean.onCellEdit}" update=":httpPolicyForm:httpTable" />
        <p:column headerText="Property">
            <h:outputText value="#{row.name}" />
        </p:column>
        <p:column headerText="Value">
            <p:cellEditor>
               <f:facet name="output"><h:outputText value="#{row.value}" /></f:facet>
               <f:facet name="input"><p:inputText value="#{row.value}" style="width:100%"/></f:facet>
           </p:cellEditor>
        </p:column>
    </p:dataTable> 
</h:form>

And here is my even listener method:

public void onCellEdit(CellEditEvent event) {
        Object oldValue = event.getOldValue();
        Object newValue = event.getNewValue();
        printRowValues();
        if(newValue != null && !newValue.equals(oldValue)) {
            logger.debug("Old: " + oldValue + ", New:" + newValue);
            FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Cell Changed", "Old: " + oldValue + ", New:" + newValue);
            FacesContext.getCurrentInstance().addMessage(null, msg);
        }
}

The method is invoked but the value of newValue is always the old value. Also, the table is never updated with the new value. However, if I click on the cell again to edit the value again it pulls up the new value. I am not sure what I am doing wrong. Please help me figure this out.

The bean is SessionScoped.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
jrobertsz66
  • 953
  • 1
  • 12
  • 29

1 Answers1

0

I was able to get this to work by performing the following step:

Moved the event listener onCellEdit() function from the HttpPolicyBean class to a new class called PolicyViewBean and made that bean ViewScoped.

I noticed that in the example on the PF demo.

BTW, I am now trying to figure out why getRows() in HttPolicyBean gets called multiple times when the scope for it is SessionScoped. Per my understanding of SessionScoped, it should only be called once when the session is first created and the list is empty.

jrobertsz66
  • 953
  • 1
  • 12
  • 29
  • 1
    "I am now trying to figure out why getRows() in HttPolicyBean gets called multiple times" http://stackoverflow.com/questions/2090033/why-jsf-calls-getters-multiple-times – Mathieu Castets Jul 13 '15 at 23:04