In Cell Editing for dynamic columns

UI Components for JSF
ealves
Posts: 3
Joined: 10 Feb 2013, 13:37

26 May 2013, 18:03

Hi anabenz,

I have the same requirements commented in this post (Cell Editing + Dynamic columns) and I have tried your solution but it didn't work for me.

I am using PF v3.5 and when I used the styleClass="ui-editable-column" it is true that it turned my table editable as you mention, BUT, when modifying its cells, it is only updating the first column cells. [...]
Hi,

I'm trying to implement Dynamic Columns + Cell Editing too and I not found a solution this problem.
When I used the styleClass="ui-editable-column" the DataTable render perfectly in EditMode in my Dynamic Columns, but the implemention of Ajax Event 'CellEdit' is not working.
I need to save the modifications in my cells edit, someone could help me with solution? Or not possible to implement the Ajax Event 'Cell Edit'?

Thanks.

adw3345
Posts: 10
Joined: 05 Sep 2012, 08:23

25 Oct 2013, 06:33

I don't have anything useful to contribute except for commiseration - I'm having the same problems with editable cells with a datatable with dynamic columns. The styleClass="ui-editable-column" trick works for me, but the CellEditEvent listener doesn't work. The listener does trigger but you can't really get useful information about what got edited.

You can find the row number using the event.getRowIndex() call, so I had some hope I'd be able to figure out some other information from the event. The event.getColumn().getClientId() gives you the id of the input value, but it's not a reliable way to figure out which cell got edited. Even if you did, the event.getOldValue() and event.getNewValue() returns nulls, so you're kind of stuck there.

Oh well, hopefully it'll be supported in a future release. It looks like one of those things that ought to work, so it can be frustrating when you hit a wall like that.

-Derrick
Primefaces 3.4.2
JBoss JSF 2.1 (version 2.0.1 Final)
Ubuntu Linux 12.04.1

irene_villa
Posts: 4
Joined: 21 Feb 2013, 22:36

29 Nov 2013, 23:35

Sorry could solve the problem? Could you help me .. please

adw3345
Posts: 10
Joined: 05 Sep 2012, 08:23

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
Primefaces 3.4.2
JBoss JSF 2.1 (version 2.0.1 Final)
Ubuntu Linux 12.04.1

shikida
Posts: 35
Joined: 29 May 2013, 06:15

18 Feb 2014, 16:26

this info should be in the demo

mackiur
Posts: 4
Joined: 20 Feb 2014, 16:28

20 Feb 2014, 18:30

ok i read all this. thx for the example, but i have a problem.

i couldn't obtain the getColumn value, it is null. Anybody has the same problem?

i also do this example:

http://forum.primefaces.org/memberlist. ... le&u=35076

but including changing the value for a direct variable. it doesn't take the value =(

thanks

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

20 Feb 2014, 20:49

wrong link...

fante76
Posts: 5
Joined: 29 May 2014, 14:43

29 May 2014, 14:45

The solution posted by anasbenz works good for me.

I've added styleClass="ui-editable-column" to p:columns.

tiagokos
Posts: 2
Joined: 20 Jan 2015, 15:52

20 Jan 2015, 17:08

Hello, sorry for the late comment but were you able to have the filtering working?

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

21 Jan 2015, 01:35

PrimeFaces 5.1.9 and newer supports cell editing with dynamic columns out of the box.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 37 guests