question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CellEditor: Dynamic columns cellEdit event

See original GitHub issue

The components p:dataTable and p:treeTable both have the following problem:

1) Environment

  • All PF, browser and AppServer versions

2) Expected behavior

  • Event.old/new values should not be null
  • onCellEditInit should be called
  • Documentation of p:cellEditor should reference p:treeTable too
  • Documentation of p:treeTable should explain, why there are no cellEditInit and cellEditCancel events documented.

3) Actual behavior

  • “cellEdit” event.old/new values are null for value expressions like #{bean.values[index]}
  • cellEditInit not signaled?

4) Steps to reproduce

Change first “val” in the upper table to “val2”. grafik grafik This is correct.

Now, change “values1” to “values11”. grafik The old and new value in the event is null, which is wrong. Additionally, there is no event fired for cellEditInit. I’d recommend, to add test cases for any event into the showcase, as just this case is missing.

Note that form of ValueExpression is absolute important for anyone, who has a data model with a dynamic length of values in a list. Note that this usecase - which seems to be quite normal - is not in you showcases, even if you have “dynamic columns”, which however are fixed to possible fields. I don’t see an other option to implement a p:dataTable with an unknown number of columns. If there is any workaround, I’d be very interested. Otherwise, could you give me some hints on how to fix it?

5) Sample XHTML

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core" xmlns:p="http://primefaces.org/ui">
<h:head />
<h:body>
  <h:form id="form">
  <p:growl id="growl" sticky="true"/>
    <p:dataTable value="#{[0]}" var="v" editMode="cell" editable="true" tableStyle="display: inline">
      <p:ajax event="cellEdit" listener="#{bean.onCellEdit}" update=":form:growl" />
      <p:ajax event="cellEditInit" listener="#{bean.onCellEditInit}" update=":form:growl" />
      <p:ajax event="cellEditCancel" listener="#{bean.onCellEditCancel}" update=":form:growl" />
      <p:columns var="c" value="#{[0,1]}">
        <p:cellEditor>
          <f:facet name="input"> 
            <p:inputText value="#{bean.val}" />
          </f:facet>
          <f:facet name="output">#{bean.val}</f:facet>
        </p:cellEditor>
      </p:columns>
    </p:dataTable>
    <p:dataTable value="#{[0]}" var="v" editMode="cell" editable="true" tableStyle="display: inline">
      <p:ajax event="cellEdit" listener="#{bean.onCellEdit}" update=":form:growl" />
      <p:columns var="c" value="#{[0,1]}">
        <p:cellEditor>
          <f:facet name="input">
            <p:inputText value="#{bean.values[c]}" />
          </f:facet>
          <f:facet name="output">#{bean.values[c]}</f:facet>
        </p:cellEditor>
      </p:columns>
    </p:dataTable>
  </h:form>
</h:body>
</html>

6) Sample bean

@SessionScoped @Named
public class Bean implements Serializable {	
	String val="val";
	public String getVal() { return val; }
	public void setVal(String val) { this.val = val; }
	
        List<String>values=new ArrayList<>(Arrays.asList("values1","values2"));
        public List<String> getValues() { return values; }
        public void setValues(List<String> values) { this.values = values;  }
	
	public void onCellEdit(CellEditEvent e) { info("cellEdit", e); }
	public void onCellEditInit(CellEditEvent e) { info("cellEditInit", e); }
	public void onCellEditCancel(CellEditEvent e) { info("cellEditCancel", e); }
	
	public static void info(String method, CellEditEvent e) {
		String message=String.format("%s: old=%s, new=%s",
				method, e.getOldValue(), e.getNewValue());
		FacesContext.getCurrentInstance().addMessage(null, 
				new FacesMessage(message));
	}
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

0reactions
mdzaebelcommented, Mar 3, 2020

I retested successfully with 8.0-SNAPSHOT for p:dataTable. However, p:treeTable does not work. Here is the sample for p:treeTable:

Bean3.java

@SessionScoped @Named
public class Bean3 implements Serializable {
  private static final long serialVersionUID = 1L;

  public class Test implements Serializable { // Content class of TreeNodes
    private static final long serialVersionUID = 1L;	
    public String value;
    public String getValue() { return value; }
    public void setValue(String value) { this.value = value; }

    public int index;
    public int getIndex() { return index; }
    public void setIndex(int index) { this.index = index; }
		
    public Test(String value, int index) { this.value=value; this.index=index; }
  }
	
  TreeNode root;
  public TreeNode getRoot() { return root; }
  public void setRoot(TreeNode root) { this.root = root; }

  public void createTreeNodes() { 
    root=new DefaultTreeNode(new Test("Root", 0), null);
	new DefaultTreeNode(new Test("One", 1), root);
	new DefaultTreeNode(new Test("Two", 2), root);
  }
  @PostConstruct public void init() { createTreeNodes(); }
	
  public void onCellEdit(CellEditEvent<?> e) { info("cellEdit", e); }
  public void onCellEditInit(CellEditEvent<?> e) { info("cellEditInit", e); }
  public void onCellEditCancel(CellEditEvent<?> e) { info("cellEditCancel", e); }
	
  public static void info(String method, CellEditEvent<?> e) {
    String message=String.format("old=%s, new=%s", e.getOldValue(), e.getNewValue());
    FacesContext.getCurrentInstance().addMessage(null, 
      new FacesMessage(FacesMessage.SEVERITY_INFO, method+":", message));
  }
}

treeTable.xhtml

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"
   xmlns:f="http://xmlns.jcp.org/jsf/core" xmlns:p="http://primefaces.org/ui" >
<h:head />
<h:body>
  <h:form id="form">
    <p:growl id="msgs" showDetail="true"/>
    <p:treeTable value="#{bean3.root}" var="var" editMode="cell" editable="true" tableStyle="width:auto">
      <p:ajax event="cellEditInit" listener="#{bean3.onCellEditInit}" update=":form:msgs"/>
      <p:ajax event="cellEdit" listener="#{bean3.onCellEdit}"  update=":form:msgs"/>
      <p:columns var="property" value="#{['value','index']}"  headerText ="#{property}">
        <p:cellEditor>
          <f:facet name="output"><h:outputText value="#{var[property]}" /></f:facet>
          <f:facet name="input"><p:inputText value="#{var[property]}" /></f:facet>
        </p:cellEditor>
      </p:columns>
    </p:treeTable>
  </h:form>
</h:body>
</html>

Reproduce

  • Click in the top/left cell and change the value. It will not change (bug).
    • The message shows cellEdit: old=One, new=One, but new should be changed.
    • Also, cellEditInit is not fired for treeTable (but for dataTable)
  • Hovever, in the second row, it works
Read more comments on GitHub >

github_iconTop Results From Across the Web

In Cell Editing for dynamic columns - Prime Community Forum
I have implemented a p:datatable with dynamic colums. The user can choose from approx 100 tables to edit, and they all have different...
Read more >
How to get old/new value of edited cell from p:cellEditor in p ...
1 Answer 1 · 1. Why is this a solution? The showcase does not use dynamic columns, while this example does... A major...
Read more >
CellEditor: Dynamic columns cellEdit event - Bountysource
The components p:dataTable and p:treeTable both have the following problem: 1) Environment. All PF, browser and AppServer versions ...
Read more >
JavaScript Data Grid: Cell Editing - AG Grid
To dynamically determine which cells are editable, a callback function can be supplied to the editable property on the Column Definition:
Read more >
Full row editing with Custom Select Editor and dynamic ...
... dynamically updated the following columns "Select editor options" ... /vue-data-grid/column-properties/#reference-editing; Cell Editor ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found