-1

I'm allocating my project to Payara Server with clustering for high avaiability. My project is in Java Web and it uses JSF Framework with Primefaces with some extended classes, like DataTable, for example (org.primefaces.component.datatable.DataTable).

As this class does not implement a serializable interface, I'm not able to succeed at the server replication failure, as the server demands all classes to be serialized.

What should I do at this situation where I need all classes to be serialized, but I don't have any control over the classes used by third parties frameworks?

  • What cannot be serialized? The JSF viewstate? – Kukeltje Jul 04 '18 at 15:13
  • One of them is DataTable attribute imported from primefaces. For exemple : import org.primefaces.component.datatable.DataTable; public DataTable dt; – lucianovcnt Jul 04 '18 at 15:15
  • Yes, that was already clear, but where is this used? In the viewstate, in your own mamaged bean? What is the 'root' class that is being serialized for replication. If it is your bean, you could mark it transient. – Kukeltje Jul 04 '18 at 15:25
  • Yes @Kukeltje, on my ManagedBean with ViewScoped. Already tried to put as transient, but did not work. – lucianovcnt Jul 04 '18 at 16:19
  • Did you try a non-serializable class of your own with transient (maybe even one with a non-serializable property as well)? Did it work? If not, the thing is not PrimeFaces related and you can search for why transient does not work. If it did, it is valuable information. And how did you make it transient: https://stackoverflow.com/questions/14582440/how-to-exclude-field-from-class-serialization-in-runtime/14582551 – Kukeltje Jul 05 '18 at 07:23
  • A code sample would help us understand what you're doing. Also any error in the logs or exception. You said that you already tried to use the `transient` keyword but you probably didn't apply it correctly. – OndroMih Jul 10 '18 at 22:54
  • Thank you guys ! persisting in my test ended up working right using transient. – lucianovcnt Jul 24 '18 at 20:46

2 Answers2

0

you need to modify serialization of your viewScoped bean that refers to the non-serializable DataTable object. To do this, you need to implement methods writeObject(java.io.ObjectOutputStream out) and readObject(java.io.ObjectInputStream in) as described in the Javadoc for Serializable. You can use the out.defaultWriteObject method to serialize all serializable fields and only write custom serialization for your DataTable object.

But I would seriously consider removing the DataTable object from serialization by marking the field with transient. DataTable is a complex object which could waste a lot of memory if included in the session. It's better to store only the data needed to recreate the DataTable object. Normally you should only keep your datamodel of the DataTable object.

OndroMih
  • 7,280
  • 1
  • 26
  • 44
  • I would indeed think you are right but OP alread y tried marking as transient according to the comments. And I also posted something about the right `'transient'` (not `@Transient)) but no response for almost a week... I'm inclined to http://idownvotedbecau.se/beingunresponsive – Kukeltje Jul 10 '18 at 08:07
0

Many users use a compoment-"binding" to viewscoped beans, which should be avoided. Please read: https://myfaces.apache.org/orchestra/component-bindings.html

Component classes are by design not serializable.

You can always lookup them lazy via the findComponent API.

tandraschko
  • 2,291
  • 13
  • 13