Rich's point is a good one. If you load an entity from a database using
Hibernate, it is a "live" object in that you can follow its references
to other objects and they will transparently get loaded from the
database too (lazy relations). However if you serialize the object then
deserialize it the object becomes "detached", and following any lazy
relation results in a LazyInitializationException. In this case,
refetching during the validate phase can in fact be quite different from
deserializing.

Also, objects in the list may not be serializable so defaulting to
preserveDataModel just isn't an option in that case.

I think your proposal is a good one in many cases, but I also think that
the "correct" solution for a particular data table depends on a number
of factors. I've started to list them, and what they imply for the
"correct" usage of a datatable - and it's got very complex!

The only thing that is quite clear is that someone should patch
t:dataTable (and maybe h:dataTable) so that on processDecodes it walks
its children and checks if any implements EditableValueHolder. If not,
it should skip fetching of the dataModel. I can't see any justification
for fetching again when the table has no input components.

I've got this on my to-do list, but unfortunately there are quite a few
things in front of it!

Cheers,

Simon


On Sat, 2006-01-14 at 15:20 +0800, Yee CN wrote: 
> Rich,
> 
> Actually my proposal is specifically to prevent the issues you described.
> Please refer to the thread "An optimised pattern for using t:dataTable -
> please verify". This is where the current thread originates from.
> 
> Regards,
> Yee
> 
> -----Original Message-----
> From: Richard Wallace [mailto:[EMAIL PROTECTED] 
> Sent: Saturday, 14 January 2006 3:04 PM
> To: MyFaces Discussion
> Subject: Re: JSF Flaw: Comopnent not preserving it state
> 
> The biggest problem I can see with making the default value for this 
> true for the dataTable component is that the DataModel could very well 
> be backed by data loaded from an ORM tool such as Hibernate.  In this 
> case, it would be very easy to run into LazyInitializationExceptions or 
> equivalent.  Also, as pointed out, if the data is loaded from the 
> database, other users interacting with the system could cause a user to 
> see stale data.  A refresh button for the table is a poor solution to 
> this, because in my experience when a user sees a new page load they 
> expect the data to be the latest.  Making them have to hit an additional 
> refresh button would just confuse them.
> 
> On a bit of a different note, something I've run into with DataTables 
> that bugs me is the way JSF handles the Master-Detail pattern.  Using 
> the traditional way of finding the object the user selected with the 
> DataModel.getRowData() method is error-prone if another user adds an 
> object that would appear in the table before the one the user is trying 
> to drill-down on.  The user could wind up with an off-by-one error, 
> getting the object above the one they selected.  I don't know what the 
> best solution to this is.  In the past I've tried to use the 
> t:updateActionListener to set an id parameter in the backing bean and 
> load just the object I'm interested in for the details as an alternative 
> to using the DataModel.getRowData() method.  But I'm not sure that's any 
> better for consistency because I'm not sure when the parameter for the 
> updateActionListener is actually set.  If it's when the master page is 
> loaded, then it will work fine.  But if it's when the view is being 
> restored when the link to go to the detail page is clicked, then this is 
> still error-prone.  Of course, it also doesn't solve the problem of 
> having to do the select for all the things that would show up in the 
> master list when all you're interested in is the single object you want 
> to get details on.
> 
> Just my 2c worth.
> 
> Rich
> 
> Yee CN wrote:
> > I definitely consider this a flaw. There is no reason why a dataTable
> should
> > behave differently from an inputText. preserveDataModel should be enforced
> > in all components and enabled by default. It should only be disabled with
> > explicit settings.
> >
> > This has been a major stumbling block for me to get a clear understanding
> of
> > the JSF technology. Judging from the discussions in this news group - I
> > think I am not the only one.
> >
> > What is the possibility of rectifying this in JSF spec?
> >
> > Regards,
> > Yee
> >
> > -----Original Message-----
> > From: Simon Kitching [mailto:[EMAIL PROTECTED] 
> > Sent: Saturday, 14 January 2006 12:15 PM
> > To: MyFaces Discussion
> > Subject: Re: AW: An optimised pattern for using t:dataTable - please
> verify.
> >
> > On Fri, 2006-01-13 at 15:27 +0100, Matthias Kahlau wrote:
> >   
> >> Hi Simon!
> >>
> >> You wrote:
> >>
> >>     
> >>> NB: The default behaviour (no preserveDataModel) is flawed because it
> >>> doesn't get (2) right for datasets that may be changed by something
> >>> other than the viewing user.
> >>>       
> >> Isn't this only a problem if the dataModel is directly backed by the
> >> database, so that the database is accessed on each call of
> getDataModel()?
> >>     
> >
> > Well, it's flawed for any "dataset that may be changed by something
> > other than the viewing user". But yes the most common situation that
> > occurs in is when an app is retrieving data from a shared database.
> >
> > When all the data is held in memory and does not change (ie is static
> > "reference" data) then of course the default behaviour is fine. However
> > that isn't often the case.
> >
> > Regards,
> >
> > Simon
> >
> >   
> 

Reply via email to