You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Michael Litherland <mi...@gmail.com> on 2007/02/13 01:05:07 UTC
Request scoped dataTables
Hi all,
I'm doing some pondering about bean scope and in particular if dataTable is
working the way it's intended. I've tried both the myfaces and tomahawk
dataTable entities and if they're filled with a request scoped bean wielding
a DataModel putting a commandLink or button in the table to provide a
detailed view of a row just causes a page reload rather than going to the
action I specify. From a considerable amount of google it seems this is a
feature of JSF, but I find that hard to believe, even if the RI is doing it
too. I've also tried playing with binding and doing downright evil stuff in
my faces-config.
So first off I apologize if this is a well trodden path in faces
discussions. If you don't mind, how do others deal with this? I can't see
making all the backing beans session scoped (though it works), and tobago's
pageFlow stuff doesn't seem practical now (and I don't even know if it would
help).
Thanks much,
Mike
Re: Request scoped dataTables
Posted by Michael Litherland <mi...@gmail.com>.
On 2/12/07, Simon Kitching <si...@rhe.co.nz> wrote:
>
> Michael Litherland wrote:
> > Sorry about not being clear. I have a dataTable that renders a
> > ListDataModel created by a request scoped bean. I understand that
> > keeping the DataModel request scoped would make it not work on the
> > return click, so as a result I tried to tie it to a session scoped
> > 'user' bean that is a managed property of all the request beans in
> > question. However a command link that called an action of either the
> > source request bean or the target request bean resulted in reloading the
> > source page as if there was no from-outcome rule for the page given the
> > action that I specified (and I tested this by using log4j to log the
> > method that I wanted called). I could diagram this or provide some
> > pseudo code if that would be helpful.
>
> Do you have an h:messages tag in this page? Normally "failed to
> navigate" problems are caused by validation failure.
Yes I do have a h:messages and copious log4j logging, but it doesn't display
any problems, which in itself is worrying.
> A more elegant solution is to put the model into a "conversation
> scope"
> > of some sort; t:saveState is one way to do this.
> >
> >
> > I'll look into this, thanks for the hint.
>
> NB: Apache Shale provides a "conversation scope" feature, and so does
> JBoss Seam. Both are more powerful than t:saveState but also more complex.
>
> Hopefully someday "conversation scope" will be part of the JSF standard
> as it's basically impossible to write a decent-sized app without it.
Haven't really looked into shale, but steam is too much integration for my
taste and gets away from the relatively XML-free nature of JSF/EJB3 (not
that XML is bad, but expression of the logic in code is ideal for
maintenance going forward). That idea sounds like what the pageFlow portion
of tobago is going for and I agree that it's a great idea.
>
> > The t:dataTable has a "preserveModel" attribute or something like
> that
> > which automatically handles this but does require the datamodel to
> be
> > serializable so it can be stored with the component tree.
> >
> >
> > Don't know about this one, eventually that datamodel may have 600+ paged
> > entities and that kind of freaks me out. Of course that's another
> > obstacle on its own.
>
> Yep, something to be careful of. However t:saveState has effectively the
> same implication, as does any other conversation-scope solution OR using
> session-scope beans. In all cases, the data is kept around until the
> user decides to do a postback or the session times out. Of course with
> session-beans there is an additional task of figuring out when to
> discard data, which "conversation scope" does for you.
>
> Note also that permitting users to use "back" buttons makes things
> really ugly. If the table state is embedded in the component tree
> (t:saveState or t:dataTable's native preserving) then this works but the
> memory implications can be nasty for large models. If the data is kept
> separate then a back-button causes mismatch between table and model.
Fortunately for this app the "users" are in themselves developers so I have
the option of saying "back is bad, mmkay?" but I agree that it's an issue
with app development in general (boy do I hate the web sometimes, but really
any serious multiuser app has to deal with it).
>
> > If the datamodel is actually backing some data that you know does
> not
> > change between render and postback (eg is static data from a
> database)
> > then the datamodel can be safely refetched during the postback
> > processing. However if the data can change this is a really bad idea
> as
> > JSF will get confused about which row is which.
> >
> >
> > In this case the data for the model won't likely change (additions are
> > infrequent). I understand the concern here.
>
> Then refetching the data on postback is probably the best solution.
I'll keep playing when time permits (this is one of those 'it must be
complete by tomorrow' (quite literally) apps), but it still seems to me that
dataTable may have issues. I'd like as badly as anybody to be able to
determine if its my app or the library's issue, hence my call for assistance
here.
Cheers,
>
> Simon
Again Simon, thanks for your reply.
Mike
Re: Request scoped dataTables
Posted by Simon Kitching <si...@rhe.co.nz>.
Michael Litherland wrote:
> Sorry about not being clear. I have a dataTable that renders a
> ListDataModel created by a request scoped bean. I understand that
> keeping the DataModel request scoped would make it not work on the
> return click, so as a result I tried to tie it to a session scoped
> 'user' bean that is a managed property of all the request beans in
> question. However a command link that called an action of either the
> source request bean or the target request bean resulted in reloading the
> source page as if there was no from-outcome rule for the page given the
> action that I specified (and I tested this by using log4j to log the
> method that I wanted called). I could diagram this or provide some
> pseudo code if that would be helpful.
Do you have an h:messages tag in this page? Normally "failed to
navigate" problems are caused by validation failure.
> A more elegant solution is to put the model into a "conversation scope"
> of some sort; t:saveState is one way to do this.
>
>
> I'll look into this, thanks for the hint.
NB: Apache Shale provides a "conversation scope" feature, and so does
JBoss Seam. Both are more powerful than t:saveState but also more complex.
Hopefully someday "conversation scope" will be part of the JSF standard
as it's basically impossible to write a decent-sized app without it.
>
> The t:dataTable has a "preserveModel" attribute or something like that
> which automatically handles this but does require the datamodel to be
> serializable so it can be stored with the component tree.
>
>
> Don't know about this one, eventually that datamodel may have 600+ paged
> entities and that kind of freaks me out. Of course that's another
> obstacle on its own.
Yep, something to be careful of. However t:saveState has effectively the
same implication, as does any other conversation-scope solution OR using
session-scope beans. In all cases, the data is kept around until the
user decides to do a postback or the session times out. Of course with
session-beans there is an additional task of figuring out when to
discard data, which "conversation scope" does for you.
Note also that permitting users to use "back" buttons makes things
really ugly. If the table state is embedded in the component tree
(t:saveState or t:dataTable's native preserving) then this works but the
memory implications can be nasty for large models. If the data is kept
separate then a back-button causes mismatch between table and model.
>
> If the datamodel is actually backing some data that you know does not
> change between render and postback (eg is static data from a database)
> then the datamodel can be safely refetched during the postback
> processing. However if the data can change this is a really bad idea as
> JSF will get confused about which row is which.
>
>
> In this case the data for the model won't likely change (additions are
> infrequent). I understand the concern here.
Then refetching the data on postback is probably the best solution.
Cheers,
Simon
Re: Request scoped dataTables
Posted by Michael Litherland <mi...@gmail.com>.
On 2/12/07, Simon Kitching <si...@rhe.co.nz> wrote:
>
> Michael Litherland wrote:
> > Hi all,
> >
> > I'm doing some pondering about bean scope and in particular if dataTable
> > is working the way it's intended. I've tried both the myfaces and
> > tomahawk dataTable entities and if they're filled with a request scoped
> > bean wielding a DataModel putting a commandLink or button in the table
> > to provide a detailed view of a row just causes a page reload rather
> > than going to the action I specify. From a considerable amount of
> > google it seems this is a feature of JSF, but I find that hard to
> > believe, even if the RI is doing it too. I've also tried playing with
> > binding and doing downright evil stuff in my faces-config.
> >
> > So first off I apologize if this is a well trodden path in faces
> > discussions. If you don't mind, how do others deal with this? I can't
> > see making all the backing beans session scoped (though it works), and
> > tobago's pageFlow stuff doesn't seem practical now (and I don't even
> > know if it would help).
> >
Putting a command link or button in a table certainly works; I've done
> it many many times. There should be an article on the wiki
> (wiki.apache.org/myfaces) that describes how to do this "master/detail"
> stuff but it appears that the apache wiki is down right now.
Thanks, Simon, for the reply.
You don't describe exactly what is happening at your end so I can only
> speculate what the root problem is, but I wonder if your problem is that
> on postback your datamodel is empty. This would fit with your second
> paragraph where you talk about bean scopes.
Sorry about not being clear. I have a dataTable that renders a
ListDataModel created by a request scoped bean. I understand that keeping
the DataModel request scoped would make it not work on the return click, so
as a result I tried to tie it to a session scoped 'user' bean that is a
managed property of all the request beans in question. However a command
link that called an action of either the source request bean or the target
request bean resulted in reloading the source page as if there was no
from-outcome rule for the page given the action that I specified (and I
tested this by using log4j to log the method that I wanted called). I could
diagram this or provide some pseudo code if that would be helpful.
It's a fundamental assumption of JSF that when a page containing a table
> is posted back to the server the datamodel used to render the table is
> available (or one with identical data).
I *think* i covered this by tying the datamodel to the session scoped user
bean.
NB: Currently, MyFaces requires this even if the table contains no input
> or command components (well, it calls the model getter anyway). I'd like
> to see MyFaces skip fetching the model in this case but that's another
> issue.
>
> The brute-force solution to making the data model available is indeed to
> put your backing bean in session-scope.
Indeed - that works, but it certainly seems inelegant.
A more elegant solution is to put the model into a "conversation scope"
> of some sort; t:saveState is one way to do this.
I'll look into this, thanks for the hint.
The t:dataTable has a "preserveModel" attribute or something like that
> which automatically handles this but does require the datamodel to be
> serializable so it can be stored with the component tree.
Don't know about this one, eventually that datamodel may have 600+ paged
entities and that kind of freaks me out. Of course that's another obstacle
on its own.
If the datamodel is actually backing some data that you know does not
> change between render and postback (eg is static data from a database)
> then the datamodel can be safely refetched during the postback
> processing. However if the data can change this is a really bad idea as
> JSF will get confused about which row is which.
In this case the data for the model won't likely change (additions are
infrequent). I understand the concern here.
Regards,
>
> Simon
>
>
Thanks again,
Mike
Re: Request scoped dataTables
Posted by Simon Kitching <si...@rhe.co.nz>.
Michael Litherland wrote:
> Hi all,
>
> I'm doing some pondering about bean scope and in particular if dataTable
> is working the way it's intended. I've tried both the myfaces and
> tomahawk dataTable entities and if they're filled with a request scoped
> bean wielding a DataModel putting a commandLink or button in the table
> to provide a detailed view of a row just causes a page reload rather
> than going to the action I specify. From a considerable amount of
> google it seems this is a feature of JSF, but I find that hard to
> believe, even if the RI is doing it too. I've also tried playing with
> binding and doing downright evil stuff in my faces-config.
>
> So first off I apologize if this is a well trodden path in faces
> discussions. If you don't mind, how do others deal with this? I can't
> see making all the backing beans session scoped (though it works), and
> tobago's pageFlow stuff doesn't seem practical now (and I don't even
> know if it would help).
>
Putting a command link or button in a table certainly works; I've done
it many many times. There should be an article on the wiki
(wiki.apache.org/myfaces) that describes how to do this "master/detail"
stuff but it appears that the apache wiki is down right now.
You don't describe exactly what is happening at your end so I can only
speculate what the root problem is, but I wonder if your problem is that
on postback your datamodel is empty. This would fit with your second
paragraph where you talk about bean scopes.
It's a fundamental assumption of JSF that when a page containing a table
is posted back to the server the datamodel used to render the table is
available (or one with identical data).
NB: Currently, MyFaces requires this even if the table contains no input
or command components (well, it calls the model getter anyway). I'd like
to see MyFaces skip fetching the model in this case but that's another
issue.
The brute-force solution to making the data model available is indeed to
put your backing bean in session-scope.
A more elegant solution is to put the model into a "conversation scope"
of some sort; t:saveState is one way to do this.
The t:dataTable has a "preserveModel" attribute or something like that
which automatically handles this but does require the datamodel to be
serializable so it can be stored with the component tree.
If the datamodel is actually backing some data that you know does not
change between render and postback (eg is static data from a database)
then the datamodel can be safely refetched during the postback
processing. However if the data can change this is a really bad idea as
JSF will get confused about which row is which.
Regards,
Simon