Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Best pratices about DataModel, Datatable and Serialization?  RSS feed

 
Matthieu Dubois
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello !

I would like to get some advices from the council of the wises

I have the following backing bean containing a list (ListDataModel):



It is displayed in the JSP with h:dataTable :



in faces-config.xml:



The problem is that when I try to serialize the HttpSession (for several reasons, one being I want to measure its size), I get a java.io.NotSerializableException on the attribute corresponding to the JSP with my list.

This makes sense as in the specs, DataModel is not marked as Serializable.

But JSF seems to save the datamodel in the view state of the page, which should not be (?).

Is there a way to do this and have the session attribute serializable?

One solution would be to inherit from ListDataModel and mark it Serializable.

Another would be (?) to change the backing bean property to:


(I tried this one, but it seems to fail)

Any another idea? Any best practice concerning DataModel, datatables and serialization?
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DataModel is an interface, and since interfaces are contracts, not objects, they cannot be serialized. I wouldn't go computing the size of any JSF datamodel except for short-term ballpark purposes, since the object is subject to radical internal changes which would almost certainly alter its size.

On thing you can do is mark the datamodel as transient and have its "get" method reconstruct it when its backing object definition is null (after de-serialization).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!