CellEditor: Dynamic columns cellEdit event
See original GitHub issueThe 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”.
This is correct.
Now, change “values1” to “values11”.
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:
- Created 4 years ago
- Comments:10 (3 by maintainers)
https://www.bountysource.com/issues/72488814-celleditor-dynamic-columns-celledit-event
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
treeTable.xhtml
Reproduce
cellEdit: old=One, new=One
, butnew
should be changed.