Hi.  I started using Wicket recently, and found have found it excellent. 
  However, although my development had gone very smoothly early on, 
recently I've started to hit a bit of a wall because of some issues 
around Wicket models (as well as my decision to switch to Wicket 1.3 
from 1.2).  I've already RTFM rather extensively (Karthik G.'s book, 
plus lots of stuff on the wiki) but I'm still very puzzled about a 
number of points.  If anyone could help with some of my questions below, 
I'd really appreciate it!


My over-arching question at this point is:  Is it a requirement that a 
model's target object be Serializable?

I ask because I've been running into a number of different issues and 
questions regarding models and serialization:

1) I tried to use a LoadableDetachableModel, partly as a way to avoid 
making my data object Serializable.  But I'm wondering if that's not 
correct.  Take for example a data object with gettters and setters for 
the following fields:  id (int), foo (string), and bar (string).  Using 
  LoadableDetachableModel, I can load the object on demand by id - and 
so all I need to do is hold the id in the LoadableDetachableModel, and 
can discard the object itself.  Thus the object doesn't need to be 
serializable.  However, lets say that a form submission by the user sets 
the foo property to "foo", and bar property to "bar".  And let's say 
further that "foo" is a valid value, but "bar" fails validation for some 
reason - which will keep the user on the same form page.  In this case 
won't a logic error result?  Since I'm not retaining (or serializing) my 
instance of the data object, but rather loading it fresh from the 
database each time, won't the "foo" value disappear?  Because when the 
model needs to access the target object, it wouldn't be accessing a 
"working" copy that had the value set to "foo", but rather a pristine 
copy from the database that had an old value?

2) How am I to handle the situation where I want to use a new (not yet 
saved) instance of a data object as the target for a model?  Since the 
object is not yet saved to the database, I can't use a 
LoadableDetachableModel to load it fresh from the database every time. 
And I can't just have the Model create a new instance each time either, 
since it looks like repeated form submissions would wind up discarding 
old values?  Is there any way to handle this situation without making my 
model target serializable?

3) You might be asking yourself:  why doesn't he just make his data 
object serializable?  And I guess I'll do that if I have to.  But I'd 
like to avoid it if possible - because it means a lot of extra work.  It 
might sound trivial to make an object serializable, but it's not.  To do 
that, you need to make sure that its entire object tree, including every 
object it references, is serializable as well.  This will not be a 
trivial task in my code, as there's numerous objects that I would need 
to make serializable.  I'd like to avoid this if I can.  So is it 
possible for a model's target object to not be serializable?  Or is 
there some way to turn off this requirement?  I noticed that in 1.2, 
when you use DEPLOYMENT mode, you wouldn't get serialization errors. 
Has that changed for 1.3?  I'm fairly certain that I won't be deploying 
Wicket with clustering (or at least not session clustering like with 
Tomcat or Terracotta - I might cluster at the database level) so why 
should I need to be forced to make all my data serializable?

4) If serialization is now a requirement for model data objects, then it 
would seem to me that it'd no longer be true that Wicket can be used 
with POJO's.  To me a POJO means a java object that doesn't need to 
extend any particular subclass or implement any particular interface - 
you can integrate it in to a framework as is without any coding changes. 
  But if model data objects are forced to implement Serializable (and so 
are all of it's referenced fields ... and all of THEIR referenced fields 
...) then they're not POJO's any longer.  There'd then be a strict 
requirement on how those objects must be implemented, right?


Can someone please help clear up some of this confusion?  As things 
stand right now, it looks as if I have no choice but to change large 
sections of my code to make it all serializable, and I'm less than 
thrilled at the prospect.  And if that's the case, then it'd seems to me 
that there's a fairly hefty cost that I'm forced to incur in using 
Wicket.  I hope that I've just misunderstood things here, and this is 
not the case.  Would appreciate any help and clarifications that people 
can offer this Wicket noob.

TIA!

DR

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to