You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Pete Poulos <pe...@gmail.com> on 2010/05/19 21:49:45 UTC
How to return a specific Page instance with an activation context?
Hi,
I'm trying to implement a standard mechanism for providing feedback to
users after they perform operations such as your standard CRUD
operations. The idea is that they click a link such as "delete" and
it performs the operation returns to that page, but with a message
along the top that says "<something> has been deleted". The vast
majority of the users state is stored in the page's activation
context, but I don't want to store the feedback message there as it
ends up complicating the context processing across all of the
applications pages.
Storing the message using @Persist(PersistenceConstants.FLASH) seems
like the way to go. However, because many of my operations are used
across multiple pages I decided to implement these operations as
separate pages that perform the operation and return to the caller.
Here is an example:
public class DeleteItem {
@Inject
private ItemDao itemDao;
@Inject
private PageRenderLinkSource pageLinkSource;
@Inject
private ComponentSource componentSource;
@CommitAfter
public Object onActivate( long id, String page ) {
return deleteItem( id, page, null );
}
@CommitAfter
public Object onActivate( long id, String page, String context ) {
return deleteItem( id, page, context );
}
private Object deleteItem( long id, String page, String context ) {
itemDao.delete( id );
// Component comp = componentSource.getPage( page );
// if( comp instanceof FlashMessagePage ) {
// ((FlashMessagePage)comp).setFlashMessage( "Bah Humbug!" );
// }
// return ???;
return context != null
? pageLinkSource.createPageRenderLinkWithContext( page, context )
: pageLinkSource.createPageRenderLink( page )
;
}
}
The crux of my problem is in the commented code. I need to return a
specific page (comp) which has had flash persisted page properties set
on it, but I also need to set the context for that page. However, all
mechanisms for creating a link with a passivation/activation context
(that I can see) only accept a page name (String) or the class object
of the page (Class). How do I return a specific page instance with an
activation context?
In the above code, it would be nice if I could do the following:
private Object deleteItem( long id, String page, String context ) {
itemDao.delete( id );
Component comp = componentSource.getPage( page );
if( comp instanceof FlashMessagePage ) {
((FlashMessagePage)comp).setFlashMessage( "Bah Humbug!" );
}
return context != null
? pageLinkSource.createPageRenderLinkWithContext( comp, context )
: pageLinkSource.createPageRenderLink( comp )
;
}
Thanks,
Pete Poulos
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: How to return a specific Page instance with an activation
context?
Posted by Howard Lewis Ship <hl...@gmail.com>.
Actually, splitting hairs, I would call field persistence the heavier
option ... you just don't see all the machinery it takes to make it
work.
On Wed, May 19, 2010 at 1:20 PM, Thiago H. de Paula Figueiredo
<th...@gmail.com> wrote:
> On Wed, 19 May 2010 17:04:25 -0300, Pete Poulos <pe...@gmail.com>
> wrote:
>
>> I considered this, but the documentation for SessionState makes it
>> sound like it is a very heavy handed solution,
>
> Why? Just curious. :)
>
>> Whereas, the
>> documentation for Flash Persistence makes it sound like the right fit.
>
> It surely fits. :)
>
> --
> Thiago H. de Paula Figueiredo
> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer, and
> instructor
> Owner, Ars Machina Tecnologia da Informação Ltda.
> http://www.arsmachina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
--
Howard M. Lewis Ship
Creator of Apache Tapestry
The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!
(971) 678-5210
http://howardlewisship.com
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: How to return a specific Page instance with an activation
context?
Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Wed, 19 May 2010 18:09:43 -0300, Pete Poulos <pe...@gmail.com>
wrote:
> * I would need to create a class to wrap the message since I don't
> like the idea of using the String type for an SSO since SSO are
> injected based on type and not name.
Absolutely right.
> * SSOs are not cleared automatically after a Flash persisted item and
> could therefore be a source of bugs if I forget to clear it to null.
Absolutely right.
> * There's also the fact that you can't check whether an SSO is null
> without forcing it to be instantiated. Therefore you have to
> introduce an extra boolean field to track whether it has been set...
Not quite right. :P Use @SessionState(create = false) and it will not be
created automatically, leaving the corresponding field null.
> creating the SSO, you should do so." However, I suspect that using
> flash persistence incurs a similar penalty, however the docs say
> nothing about this.
From what I understood from the FlashPersistentFieldStrategy and
AbstractSessionPersistentFieldStrategy classes, just checking if a
@Persist("flash") is null doesn't create a session.
> That being the case I wasn't clear whether SSOs
> incurred a higher penalty than using flash persistence or not.
Just a little bit more of memory comsumption because of the extra class.
--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: How to return a specific Page instance with an activation
context?
Posted by Pete Poulos <pe...@gmail.com>.
>> I considered this, but the documentation for SessionState makes it
>> sound like it is a very heavy handed solution,
>
> Why? Just curious. :)
>From an implementation perspective...
* I would need to create a class to wrap the message since I don't
like the idea of using the String type for an SSO since SSO are
injected based on type and not name.
* SSOs are not cleared automatically after a Flash persisted item and
could therefore be a source of bugs if I forget to clear it to null.
* There's also the fact that you can't check whether an SSO is null
without forcing it to be instantiated. Therefore you have to
introduce an extra boolean field to track whether it has been set...
>.<
>From a performance perspective:
* from the docs "Scalable web applications do not create the
server-side session needlessly. If you can avoid creating the session,
especially on first access to your web application, you will be able
to handle an order of magnitude more users. So, if you can avoid
creating the SSO, you should do so." However, I suspect that using
flash persistence incurs a similar penalty, however the docs say
nothing about this. That being the case I wasn't clear whether SSOs
incurred a higher penalty than using flash persistence or not.
* I'm just speculating here, but since flash persistence has a well
defined lifespan I imagine that there are optimizations that could be
done to improve it's performance especially with respect to server
clustering (even if no optimizations are done currently). However, as
I have little experience with this kind of thing I could be very
wrong.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: How to return a specific Page instance with an activation
context?
Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Wed, 19 May 2010 17:04:25 -0300, Pete Poulos <pe...@gmail.com>
wrote:
> I considered this, but the documentation for SessionState makes it
> sound like it is a very heavy handed solution,
Why? Just curious. :)
> Whereas, the
> documentation for Flash Persistence makes it sound like the right fit.
It surely fits. :)
--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: How to return a specific Page instance with an activation
context?
Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Wed, 19 May 2010 18:25:19 -0300, Pete Poulos <pe...@gmail.com>
wrote:
> So, if the only thing I'm using the session for is to store this user
> feedback message am I going to suffer a huge scalability hit as
> indicated in the SSO docs?
>
> "Scalable web applications do not create the side session needlessly.
> If you can avoid creating the session, on first access to your web
> application, you will be able to handle an order of magnitude more
> users. So, if you can avoid the SSO, you should do so."
Both flash and SSO persistence are session persistence, so using one or
other don't change performance. Avoiding using the session would.
The text above could be a little more explicit in to refer to
session-based storage, not only SSO.
> I also saw a message in the archives that suggested that any use of a
> Form stores an object for validation within the session as well.
That's the default behavior.
--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: How to return a specific Page instance with an activation
context?
Posted by Pete Poulos <pe...@gmail.com>.
So, if the only thing I'm using the session for is to store this user
feedback message am I going to suffer a huge scalability hit as
indicated in the SSO docs?
"Scalable web applications do not create the side session needlessly.
If you can avoid creating the session, on first access to your web
application, you will be able to handle an order of magnitude more
users. So, if you can avoid the SSO, you should do so."
I also saw a message in the archives that suggested that any use of a
Form stores an object for validation within the session as well.
I don't have a lot of experience developing web applications and I
don't know how to measure this sort of thing to know if it's something
that i need to be concerned with or not.
Thanks,
Pete Poulos
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: How to return a specific Page instance with an activation
context?
Posted by Josh Canfield <jo...@gmail.com>.
> I considered this, but the documentation for SessionState makes it
> sound like it is a very heavy handed solution, Whereas, the
> documentation for Flash Persistence makes it sound like the right fit.
Both @Persist (flash, and session) and @SessionState (via
ApplicationStateManager) use the HttpSession to store the value. The
difference is that with @Persist it's tied to the particular page via
naming of the attribute key and @SessionState does not, making it
available across pages. Flash persistence simple deletes the item out
of the session after it has been read once.
Josh
On Wed, May 19, 2010 at 1:04 PM, Pete Poulos <pe...@gmail.com> wrote:
> Hi Thiago,
>
> Thanks for your quick reply.
>
>
>> Instead of using @Persist, why not creating a class to hold the message and
>> use it as @SessionState? Just remember to clear the field with the message
>> after it is requested.
>
> I considered this, but the documentation for SessionState makes it
> sound like it is a very heavy handed solution, Whereas, the
> documentation for Flash Persistence makes it sound like the right fit.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
--
--
http://www.bodylabgym.com - a private, by appointment only, one-on-one
health and fitness facility.
--
http://www.ectransition.com - Quality Electronic Cigarettes at a
reasonable price!
--
TheDailyTube.com. Sign up and get the best new videos on the internet
delivered fresh to your inbox.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: How to return a specific Page instance with an activation
context?
Posted by Pete Poulos <pe...@gmail.com>.
Hi Thiago,
Thanks for your quick reply.
> Instead of using @Persist, why not creating a class to hold the message and
> use it as @SessionState? Just remember to clear the field with the message
> after it is requested.
I considered this, but the documentation for SessionState makes it
sound like it is a very heavy handed solution, Whereas, the
documentation for Flash Persistence makes it sound like the right fit.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: How to return a specific Page instance with an activation
context?
Posted by Josh Canfield <jo...@gmail.com>.
> Instead of using @Persist, why not creating a class to hold the message and
> use it as @SessionState? Just remember to clear the field with the message
> after it is requested.
This is the strategy that I use. I have a UserMessageHolder object
stored as @SessionState and have a component that renders the
messages, much like t:error. This way in your code you simply write
userMessage.info("'%s' has been deleted."); and the next time the page
renders (that has the UserMessages component) the message is
displayed.
Josh
On Wed, May 19, 2010 at 12:53 PM, Thiago H. de Paula Figueiredo
<th...@gmail.com> wrote:
> On Wed, 19 May 2010 16:49:45 -0300, Pete Poulos <pe...@gmail.com>
> wrote:
>
>> Hi,
>
> Hi!
>
> Instead of using @Persist, why not creating a class to hold the message and
> use it as @SessionState? Just remember to clear the field with the message
> after it is requested.
>
> --
> Thiago H. de Paula Figueiredo
> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer, and
> instructor
> Owner, Ars Machina Tecnologia da Informação Ltda.
> http://www.arsmachina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
--
--
http://www.bodylabgym.com - a private, by appointment only, one-on-one
health and fitness facility.
--
http://www.ectransition.com - Quality Electronic Cigarettes at a
reasonable price!
--
TheDailyTube.com. Sign up and get the best new videos on the internet
delivered fresh to your inbox.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: How to return a specific Page instance with an activation
context?
Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Wed, 19 May 2010 16:49:45 -0300, Pete Poulos <pe...@gmail.com>
wrote:
> Hi,
Hi!
Instead of using @Persist, why not creating a class to hold the message
and use it as @SessionState? Just remember to clear the field with the
message after it is requested.
--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: How to return a specific Page instance with an activation
context?
Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Wed, 19 May 2010 16:56:24 -0300, Pete Poulos <pe...@gmail.com>
wrote:
> Btw, it's not at all intuitive that this would work. I guess what's
> happening is that when you acquire a page instance and set (persisted)
> values on it, then those are the values that will be used the next
> time the page is accessed?
When you set a @Persist field with a value, a specially-named session
attribute receives this value. When a new request arrives, a page instance
is checked out of the pool and when you read this field, actually it reads
this session attribute back.
--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: How to return a specific Page instance with an activation
context?
Posted by Pete Poulos <pe...@gmail.com>.
So... I just tried the following and it worked, so I guess I answered
my own question. Sorry for troubling you folks.
private Object deleteItem( long id, String page, String context ) {
itemDao.delete( id );
Component comp = componentSource.getPage( page );
if( comp instanceof FlashMessagePage ) {
((FlashMessagePage)comp).setFlashMessage( "Bah Humbug!" );
}
return context != null
? pageLinkSource.createPageRenderLinkWithContext( page, context )
: pageLinkSource.createPageRenderLink( page )
;
}
Btw, it's not at all intuitive that this would work. I guess what's
happening is that when you acquire a page instance and set (persisted)
values on it, then those are the values that will be used the next
time the page is accessed?
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org