You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by César Lesc <ce...@gmail.com> on 2007/09/12 19:27:35 UTC

T5 - Inject an Application State Object into a Service

I need to use data stored in an ASO (user information) to process the a
requests in a service object, i guess the service object must be in
perthread scope, because the ASO stores his data in the session, but the
@ApplicationState annotation is not working inside the service. Finally i
found the RequestGlobals Service to store and retrieve data in the session
inside a service, but i feel that should be a better approach. May be i'm
missing something.

Thanks in advance

César.

Re: T5 - Inject an Application State Object into a Service

Posted by César Lesc <ce...@gmail.com>.
Well, many of the methods of this service needs the user name (from the ASO)
for security constraints, i don't want pollute the service interface with a
parameter that is almost a constant (for each user), when can be easily
grabbed from the session, and don't have to repeat the code to obtain the
ASO in every page that use the service.

César.

On 9/12/07, lasitha <la...@gmail.com> wrote:
>
> Sorry to ask the obvious, but is there some reason you can't just pass
> the ASO into the relevant service method:
>
> class Page {
> @ASO aso;
> @Inject service;
> void onAction() {
>    service.doSomethingWith(aso);
> }
> }
>
> I'm sure your situation's more complicated - just had to get the
> obvious out of the way :)
> Cheers.
>
> On 9/12/07, César Lesc <ce...@gmail.com> wrote:
> > I need to use data stored in an ASO (user information) to process the a
> > requests in a service object, i guess the service object must be in
> > perthread scope, because the ASO stores his data in the session, but the
> > @ApplicationState annotation is not working inside the service. Finally
> i
> > found the RequestGlobals Service to store and retrieve data in the
> session
> > inside a service, but i feel that should be a better approach. May be
> i'm
> > missing something.
> >
> > Thanks in advance
> >
> > César.
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: T5 - Inject an Application State Object into a Service

Posted by lasitha <la...@gmail.com>.
Sorry to ask the obvious, but is there some reason you can't just pass
the ASO into the relevant service method:

class Page {
  @ASO aso;
  @Inject service;
  void onAction() {
    service.doSomethingWith(aso);
  }
}

I'm sure your situation's more complicated - just had to get the
obvious out of the way :)
Cheers.

On 9/12/07, César Lesc <ce...@gmail.com> wrote:
> I need to use data stored in an ASO (user information) to process the a
> requests in a service object, i guess the service object must be in
> perthread scope, because the ASO stores his data in the session, but the
> @ApplicationState annotation is not working inside the service. Finally i
> found the RequestGlobals Service to store and retrieve data in the session
> inside a service, but i feel that should be a better approach. May be i'm
> missing something.
>
> Thanks in advance
>
> César.
>

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


Re: T5 - Inject an Application State Object into a Service

Posted by Kevin Menard <km...@servprise.com>.
In T4, you'd have something like the following to grab a global Cayenne
DataContext:

public void setDataContext(final ApplicationStateManager asm)
{
     this.dc = (DataContext) asm.get("global-data-context");
}

Exposing the name of the ASO and having to do a cast is not nice.  I'll have
to check out the T5 IoC config to see how things might be better there.  The
snippet you posted seems to address the problems.

-- 
Kevin


On 9/12/07 4:53 PM, in article
83898A32-C348-4BF0-9AF7-4919693A8496@scazdl.org, "Robert Zeigler"
<ro...@scazdl.org> wrote:

> Hm... it would certainly be nice if a service could have an ASO
> injected into it directly, but that would then mandate a particular
> scope to your service.
> I personally like the approach of injecting the ASM into the service
> and grabbing your ASO's from there.  Not familiar with the T4
> ApplicationStateManager service, but the T5 version hasn't been
> painful to use at all:
> 
> User u = asm.get(User.class);
> u....
> 
> It'll create your ASO's for you, too, if they don't exist yet (you
> can also check to see if they exist if you want to avoid creating them).
> 
> Anyway, that's definitely the right way for Cesar to go.
> 
> Robert
> 
> On Sep 12, 2007, at 9/121:23 PM , Kevin Menard wrote:
> 
>> Hmm . . . I haven't really gotten my feet wet with T5 yet.  Does
>> this mean
>> that it will still only inject into page classes, as is the case
>> with T4?  I
>> was hoping with the move to POJOs that you could inject into arbitrary
>> classes, such as services.  The ASM is a pain to use.
>> 
>> -- 
>> Kevin
>> 
>> 
>> On 9/12/07 2:09 PM, in article 46E82B4B.9080808@fsadev.com, "Filip S.
>> Adamsen" <fs...@fsadev.com> wrote:
>> 
>>> Have a look at the ApplicationStateManager service:
>>> http://tapestry.apache.org/tapestry5/tapestry-core/apidocs/org/
>>> apache/tapestry
>>> /services/ApplicationStateManager.html
>>> 
>>> -Filip
>>> 
>>> César Lesc skrev:
>>>> I need to use data stored in an ASO (user information) to process
>>>> the a
>>>> requests in a service object, i guess the service object must be in
>>>> perthread scope, because the ASO stores his data in the session,
>>>> but the
>>>> @ApplicationState annotation is not working inside the service.
>>>> Finally i
>>>> found the RequestGlobals Service to store and retrieve data in
>>>> the session
>>>> inside a service, but i feel that should be a better approach.
>>>> May be i'm
>>>> missing something.
>>>> 
>>>> Thanks in advance
>>>> 
>>>> César.
>>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>> 
>>> 
>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 



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


Re: T5 - Inject an Application State Object into a Service

Posted by Robert Zeigler <ro...@scazdl.org>.
Hm... it would certainly be nice if a service could have an ASO  
injected into it directly, but that would then mandate a particular  
scope to your service.
I personally like the approach of injecting the ASM into the service  
and grabbing your ASO's from there.  Not familiar with the T4  
ApplicationStateManager service, but the T5 version hasn't been  
painful to use at all:

User u = asm.get(User.class);
u....

It'll create your ASO's for you, too, if they don't exist yet (you  
can also check to see if they exist if you want to avoid creating them).

Anyway, that's definitely the right way for Cesar to go.

Robert

On Sep 12, 2007, at 9/121:23 PM , Kevin Menard wrote:

> Hmm . . . I haven't really gotten my feet wet with T5 yet.  Does  
> this mean
> that it will still only inject into page classes, as is the case  
> with T4?  I
> was hoping with the move to POJOs that you could inject into arbitrary
> classes, such as services.  The ASM is a pain to use.
>
> -- 
> Kevin
>
>
> On 9/12/07 2:09 PM, in article 46E82B4B.9080808@fsadev.com, "Filip S.
> Adamsen" <fs...@fsadev.com> wrote:
>
>> Have a look at the ApplicationStateManager service:
>> http://tapestry.apache.org/tapestry5/tapestry-core/apidocs/org/ 
>> apache/tapestry
>> /services/ApplicationStateManager.html
>>
>> -Filip
>>
>> César Lesc skrev:
>>> I need to use data stored in an ASO (user information) to process  
>>> the a
>>> requests in a service object, i guess the service object must be in
>>> perthread scope, because the ASO stores his data in the session,  
>>> but the
>>> @ApplicationState annotation is not working inside the service.  
>>> Finally i
>>> found the RequestGlobals Service to store and retrieve data in  
>>> the session
>>> inside a service, but i feel that should be a better approach.  
>>> May be i'm
>>> missing something.
>>>
>>> Thanks in advance
>>>
>>> César.
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org


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


Re: T5 - Inject an Application State Object into a Service

Posted by "Filip S. Adamsen" <fs...@fsadev.com>.
The documentation does actually mention the ApplicationStateManager 
service, and if you take a look at the Javadocs, it's mentioned all over 
in the application state related classes.

-Filip

César Lesc skrev:
> Thank you all for the advice, I'm using now the
> ApplicationStateManager service, its look better than using the
> RequestGlobals, the T5 core Application State documentation does not
> mention this service but i think it should because is very useful.
> 
> César.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 

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


Re: T5 - Inject an Application State Object into a Service

Posted by César Lesc <ce...@gmail.com>.
Thank you all for the advice, I'm using now the
ApplicationStateManager service, its look better than using the
RequestGlobals, the T5 core Application State documentation does not
mention this service but i think it should because is very useful.

César.

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


Re: T5 - Inject an Application State Object into a Service

Posted by "Filip S. Adamsen" <fs...@fsadev.com>.
I usually expose commonly used ASOs through a wrapper service, like 
CurrentUser for a User ASO. Works quite nice and gives me a place to put 
various user related methods.

-Filip

Kevin Menard skrev:
> Hmm . . . I haven't really gotten my feet wet with T5 yet.  Does this mean
> that it will still only inject into page classes, as is the case with T4?  I
> was hoping with the move to POJOs that you could inject into arbitrary
> classes, such as services.  The ASM is a pain to use.
> 

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


Re: T5 - Inject an Application State Object into a Service

Posted by Kevin Menard <km...@servprise.com>.
Hmm . . . I haven't really gotten my feet wet with T5 yet.  Does this mean
that it will still only inject into page classes, as is the case with T4?  I
was hoping with the move to POJOs that you could inject into arbitrary
classes, such as services.  The ASM is a pain to use.

-- 
Kevin


On 9/12/07 2:09 PM, in article 46E82B4B.9080808@fsadev.com, "Filip S.
Adamsen" <fs...@fsadev.com> wrote:

> Have a look at the ApplicationStateManager service:
> http://tapestry.apache.org/tapestry5/tapestry-core/apidocs/org/apache/tapestry
> /services/ApplicationStateManager.html
> 
> -Filip
> 
> César Lesc skrev:
>> I need to use data stored in an ASO (user information) to process the a
>> requests in a service object, i guess the service object must be in
>> perthread scope, because the ASO stores his data in the session, but the
>> @ApplicationState annotation is not working inside the service. Finally i
>> found the RequestGlobals Service to store and retrieve data in the session
>> inside a service, but i feel that should be a better approach. May be i'm
>> missing something.
>> 
>> Thanks in advance
>> 
>> César.
>> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 



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


Re: T5 - Inject an Application State Object into a Service

Posted by "Filip S. Adamsen" <fs...@fsadev.com>.
Have a look at the ApplicationStateManager service:
http://tapestry.apache.org/tapestry5/tapestry-core/apidocs/org/apache/tapestry/services/ApplicationStateManager.html

-Filip

César Lesc skrev:
> I need to use data stored in an ASO (user information) to process the a
> requests in a service object, i guess the service object must be in
> perthread scope, because the ASO stores his data in the session, but the
> @ApplicationState annotation is not working inside the service. Finally i
> found the RequestGlobals Service to store and retrieve data in the session
> inside a service, but i feel that should be a better approach. May be i'm
> missing something.
> 
> Thanks in advance
> 
> César.
> 

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