• Post Reply Bookmark Topic Watch Topic
  • New Topic

Multiples expanded PrimeFaces's DataTable's rows misbehavior

 
Daniel Barcellos
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you kindly help me with this issue?

I'm not sure whether or not this is a datatable's row expansion misbehavior or am I doing something wrong. I'll be as simple as possible with the problem's description.

First, try making a DataTable like PrimeFaces's showcase for instance with a list of Car's in wich you may "change" car's color. It's simple!

Then implement its rowExpansion in order to do the partial processing of a property action listener set via commandButton. Till there, everything is all right. So now try expand the last row and after that try expanding middle's one then click over commandButton of the first expanded row then you'll notice that the property action listener set will be pointed or related to the second expanded row. In my example I juse populate datatable's with 3 rows.

If you try to expand only one row you get the expected behavior.

It seems that the expansion process overwrite previous processed model or some sort of other misbehavior that's away from knowledge.

See the following snippets.



Bean



For those who will point the cause of issue the fact I'm using



this misbehavior is also noticed with either



This example does not function with bean set as neither as RequestScoped nor ViewScoped.

Am I doing something wrong or this could be an issue? Any tips will be appreciated.

Thanks,
 
Daniel Barcellos
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way I'm using PrimeFaces 3.5 + JSF 2.1.4 + Tomcat 7.14 and I noted that possible issue using PrimeFaces 4.0-SNAPSHOT as well.
 
Tim Holloway
Bartender
Posts: 18413
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To properly track the active row in a dataTable, I do not recommend binding the list of cars directly to the datatable (via the "value="). Instead add a property of type ListDataModel to your backing bean, construct a ListDataModel object to be its value and wrap your car list in that. For example:


You can then reference your datamodel in the AJAX listener:


If you do not construct a DataModel, JSF is going to do so anyway. It needs the DataModel to hold extra JSF-specific information about the table in a way that allows the actual table data (wrapped data) to remain simple POJOs instead of forcing them to be JSF-specific object types. But if JSF constructs the DataModel for you, you won't have an accessible object to invoke getRowData on in order to find out which row was selected. The automatically-constructed DataModel is anonymous and not stored in your backing bean like one that you create yourself would be.

To use a dataTable you cannot use Request Scope. The DataModel needs to preserve vital information between requests, and Request scope would result in that information being destroyed and a new, blank (useless) DataModel being constructed. You need at least View scope. This is one of the reasons why I say that Request Scope is almost totally useless in JSF.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!