You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Ryan <cr...@gmail.com> on 2005/09/24 06:53:54 UTC

Tapestry4, ASOs, and stateless operation question

Using tapestry 4 and an application state object holding user
information I would like to write some code that does X when the user
is logged in and Y otherwise. Also I would like to remain stateless
for as long as possible for performance reasons.

In tapestry 3 I would do something like this:

if(visit != null && visit.isAuthenticated()) {

} else { ... }

In tapestry 4 I have the nice option of injecting the user data ASO
into my page and calling getUserData() to retrieve it. The problem is
that as soon as I call getUserData() it will cause my application to
go stateful. The only method I have seen to avoid this is to use the
StateObjectPersistenceManager to determine if that ASO exists. The
problem with this approach is that I cant inject the ASO into my page
so I am forced to retrieve it myself then cast it to the correct type
and continue my logic:

if (sessionScopeManager.exists(name) &&
((UserData)sessionScopeManager.get(name, null)).isAuthenticated()) {

} else {...}

I think we all can agree that this syntax is less than desirable and
quite a pain for such a common operation.

Is there a better way to accomplish this using tapestry 4 as it is
today or would it be a nice to have to be able to inject a property
with null if the ASO has not been created yet?

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Tapestry4, ASOs, and stateless operation question

Posted by Kent Tong <ke...@cpttm.org.mo>.
Ryan <crumley <at> gmail.com> writes:

> True, what would be nice though if there were some way of telling the
> getter not to create the ASO if it doesn't exist. That way a client
> does not have to use the StateObjectPersistenceManager to determine if
> the ASO exists (similar to how tapestry3 getVisit() from a page or
> component did not create the visit if it didnt exist, it returned
> null).

True. I'm sure Howard is well aware of this problem. I just don't
know how or when he is going to solve this problem. There is already
a feature request for this 
(http://issues.apache.org/jira/browse/TAPESTRY-573). So, you may
vote for it.

--
Author of a book for learning Tapestry (http://www.agileskills2.org/EWDT)


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Tapestry4, ASOs, and stateless operation question

Posted by Ryan <cr...@gmail.com>.
On 9/27/05, Kent Tong <ke...@cpttm.org.mo> wrote:
> Ryan <crumley <at> gmail.com> writes:
> > In tapestry 4 I have the nice option of injecting the user data ASO
> > into my page and calling getUserData() to retrieve it. The problem is
> > that as soon as I call getUserData() it will cause my application to
> > go stateful. The only method I have seen to avoid this is to use the
> > StateObjectPersistenceManager to determine if that ASO exists. The
> > problem with this approach is that I cant inject the ASO into my page
> > so I am forced to retrieve it myself then cast it to the correct type
> > and continue my logic:
>
> You can still inject the ASO. As long as you don't call the getter,
> the ASO won't be created.

True, what would be nice though if there were some way of telling the
getter not to create the ASO if it doesn't exist. That way a client
does not have to use the StateObjectPersistenceManager to determine if
the ASO exists (similar to how tapestry3 getVisit() from a page or
component did not create the visit if it didnt exist, it returned
null).

Current tapestry 4:
@InjectState("userData")
public UserData getUserData();
@InjectObject(...)
public StateObjectPersistenceManager  getPersistenceManager();
...
if(getPersistenceManager().exists("userData") &&
getUserData().isAuthenticated() ) {
   ...
}

Simplified suggestion?:

@InjectState("userData" forceCreate=false)
public UserData getUserData();
...
if(getUserData() != null && getUserData().isAuthenticated() ) {
   ...
}

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Tapestry4, ASOs, and stateless operation question

Posted by Kent Tong <ke...@cpttm.org.mo>.
Ryan <crumley <at> gmail.com> writes:

> In tapestry 4 I have the nice option of injecting the user data ASO
> into my page and calling getUserData() to retrieve it. The problem is
> that as soon as I call getUserData() it will cause my application to
> go stateful. The only method I have seen to avoid this is to use the
> StateObjectPersistenceManager to determine if that ASO exists. The
> problem with this approach is that I cant inject the ASO into my page
> so I am forced to retrieve it myself then cast it to the correct type
> and continue my logic:

You can still inject the ASO. As long as you don't call the getter,
the ASO won't be created.

--
Author of a book for learning Tapestry (www.agileskills2.org/EWDT)


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org