In Cell Editing for dynamic columns

UI Components for JSF
robsonhermes
Posts: 1
Joined: 31 Jul 2015, 22:13

31 Jul 2015, 22:24

Hi optimus.prime

You said PrimeFaces 5.1.9 and above should support cellEditEvent with dynamic columns. I had the same issue with 5.2.0, newvalue and oldvalue are null.

Is it being supported in a Elite version only or should be working in Community version as well?

anilpatile
Posts: 1
Joined: 04 Jan 2017, 14:17

04 Jan 2018, 16:41

Hi, I am also hitting same issue with 6.0. Can any body help me on this.

gaulth
Posts: 1
Joined: 25 Sep 2017, 21:17

23 Jul 2018, 06:15

Thanks a lot for this it really help me!

Currently
JSF 2.2
Primefaces 6.2

The datatable + c:for each (with column inside) didn't work for me, I had to use the columns element inside the datatable not including the cell edit p:ajax instead of that i included a p:ajax event blux on the input field and now it works.
I wanted to add the code to show the example but its in work office and the security it's very high to share anything and looks something like this
<p:datatable value {general bean } var = D0>
<column>
<p:datatable value= {D0.list<list<string>> property}> var =D1 >
<columns value={bean with the index> var D2 >
<f:facet name="output">
<h:outputText value="#{D1[D2]}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{D1[D2]}" />
<p:ajax event=blur actionListener=(bean.keyuphandler()} />
</f:facet>
<columns />
<p:datatable/>
<column>
<p:datatable/>
Thanks a lot again!


adw3345 wrote:
22 Dec 2013, 23:28
Ok I successfully figured out my dymanic column problem. I used Tosh's example to make my own:

Code: Select all

  

        <p:dataTable value="#{ityteacher.gradebook.columnValues}" var="columnValues" id="currentGrades" tableStyle="table-layout:auto" editable="true" editMode="cell" widgetVar="gradeBook" scrollable="true">
	     
	      <p:ajax event="cellEdit" listener="#{ityteacher.onGradeCellEdit}" />
	           
	      <c:forEach items="#{ityteacher.gradebook.columnNames}" var="column" varStatus="colLoopStatus">
            <p:column headerText="#{column}">
               <p:cellEditor>
                  <f:facet name="output">
                     <h:outputText value="#{columnValues[colLoopStatus.index]}" />
                  </f:facet>
                  <f:facet name="input">
                     <p:inputText value="#{columnValues[colLoopStatus.index]}"  />
                  </f:facet>
               </p:cellEditor>      
            </p:column>
         </c:forEach>
         
	   </p:dataTable>
The absolute important thing to make this work at all is that the getGradebook() function in this example must only be created once upon construction.

So I needed to do this:

Code: Select all


public GradeBook getGradebook(){
		
       if(gradeBook==null){
               ........
       }

       return gradeBook;

}
If you keep regenerating the gradeBook values, the "new" and "old" values will always be 'null'.

Also one peice of trivia, you can get the row of the value changed easily through

Code: Select all

 public void onGradeCellEdit(CellEditEvent event) {
         int row = event.getRowIndex();
}
But if you want to get the column that changed, you find out through the column header:

Code: Select all

 public void onGradeCellEdit(CellEditEvent event) {
         String column = event.getColumn().getHeaderText();
}
So when a change is made, you'll have this information:

Old value
New value
Numeric Row indicator
Header string of column

Here is the structure for "Gradebook" as shown above, FYI:

Code: Select all

public class GradeBook {
	
	List<String> columnNames;
	
	List<List<String>> columnValues;

	public List<String> getColumnNames() {
		return columnNames;
	}

	public void setColumnNames(List<String> columnNames) {
		this.columnNames = columnNames;
	}

	public List<List<String>> getColumnValues() {
		return columnValues;
	}

	public void setColumnValues(List<List<String>> columnValues) {
		this.columnValues = columnValues;
	}
		
}

-Derrick

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 44 guests