• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Best pratices about DataModel, Datatable and Serialization?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Saloon Keeper
Posts: 27764
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
They worship nothing. They say it's because nothing lasts forever. Like this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic