On Sun, 2006-01-15 at 01:18 +0800, Yee CN wrote:
> Simon,
>
> It is a lot more complex than it looks on the surface. Looks like I have
> opened a can of worms.
Yep :-)
>
> Firstly Hibernate LazyInitializationException problem is inherent in the
> SessionPerRequest pattern. It is universal to all web based framework, so it
> is not unique to JSF. There are attempts to circumvent this - the SEAM
> framework is an example; it is based on JSF/EJB3. It is a well known problem
> that everybody learned to deal with it after a while.
Agreed. All that Rich was pointing out is that in some cases,
serialize/deserialize (what you were recommending) behaves differently
from refetch (the current default). So users will need to know about
both possible solutions and choose between them depending on their
circumstances.
>
> Secondly the 'correct' behavior should not depend on any particular use
> case. It is simply that Restore-View should do what it says - to restore in
> the server the view that was being rendered to the browser. That would
> include the component tree as well as the data being displayed.
I think that h:dataTable is different from components like h:inputText.
The difference is that the former's associated data is *user model*
objects, while the latter component's data is simply a *java standard
datatype*.
The select components (eg h:selectOneMenu) probably have the same issues
as h:dataTable if the option to bind the value to a Map object is used.
And currently I bet both the RI and MyFaces use the same approach as
currently used by h:dataTable, ie that after submit the component
refetches the data from the user model. I haven't checked that, though,
so correction welcome.
>
> At this stage I still feel that what I proposed in my last posting is the
> right approach. There is no ambiguity semantically. Yes the dataModel will
> have to be serializable, but I do not see any solution to this problem
> otherwise.
>
> As a point of reference, this is how ASP.NET works - its dataTable is
> basically a grid, you would do whatever to populate the grid, and from there
> you will be working with rows and columns. There is not dataModel as such.
> It is a simpler framework, but does not suffer the problems we are facing
> here.
I would be interested in learning more about how ASP.NET deals with
this. What exactly happens when a dataTable is associated with user
objects?
>
> >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 think this is not going to work - as the datatables are generally not
> editable, but yet we still need to know which row is being clicked on and
> the corresponding record data.
Good point. Any command component in the table also needs to have its
decode called, and the table associated with the correct DataModel
component at that time. This is a lot more common than input components
in a table, so my suggested optimisation (while still valid I think)
won't help in as many situations as I'd hoped.
>
> I think this problem should be addressed at the JSF spec level - not at the
> level of any particular implementation. At present t:dataTable is workable
> with the patterns that I proposed. But h:dataTable is definitely
> problematic.
I think the preserveDataModel functionality can be emulated by simply
using a t:saveState component to save the data model explicitly. This
means that your pattern can be applied to h:dataTable too.
public class MyBackingBean {
private DataModel dataModel;
public DataModel getDataModel() {
if (this.dataModel != null)
return this.dataModel;
// create and populate the dataModel
}
public void setDataModel(DataModel model) {
this.dataModel = model;
}
}
in page:
<t:saveState id="dataModel" value="#{backingBean.dataModel}"/>
<h:dataModel value="#{backingBean.dataModel}" ....>
I haven't tested this, but don't see why it wouldn't work.
Regards,
Simon