You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Mahmut Izci <ma...@freenet.de> on 2006/02/09 10:58:57 UTC

injected session object in service always null

Hi,

I'm using several engine services in my application and
this services must get access to the application's session object.

In hivemind.xml i defined a session object:

<contribution configuration-id="tapestry.state.ApplicationObjects">
  <state-object name="mySessionObject" scope="session">
    <create-instance class="com.my.application.MySessionObject"/>
  </state-object> 
</contribution>

Then I injected this into my service:

  <service-point id="MyService" 
interface="org.apache.tapestry.engine.IEngineService">
    <invoke-factory>
      <construct class="com.my.application.MyService">
        <set-object property="exceptionReporter" 
value="infrastructure:requestExceptionReporter"/>
        <set-object property="response" value="infrastructure:response"/>
        <set-object property="linkFactory" 
value="infrastructure:linkFactory"/>
        <set-object property="request" value="infrastructure:request"/>
        /<set-object property="mySessionObject" 
value="app-property:mySessionObject"/>/
      </construct>
    </invoke-factory>
  </service-point>

This session object is always not initialized and is null when I access 
it out of my service.
But when i inject the session object into the pages, it is initialized.

How can an engine service get access to the session object?

Thanks
Mahmut

Re: injected session object in service always null

Posted by Mahmut Izci <ma...@freenet.de>.
Hi Gerald,

now it works!

thank you much
Mahmut


Gerald Schöffel schrieb:
> Hi Mahmut,
>
> you could inject a ApplicationStateManager instead.
>
> In your service:
>
> private ApplicationStateManager stateManager ;
> public ApplicationStateManager getStateManager() {
>     return stateManager;
> }
> public void setStateManager(ApplicationStateManager stateManager) {
>     this.stateManager = stateManager;
> }
>
> In hivemodule.xml:
>
> <set-object property="stateManager" 
> value="infrastructure:applicationStateManager"/>
>
> To get access to your ASOs you can do the following:
>
> stateManager.get("name_of_your_aso_in_hivemodule_xml")
> stateManager.exists("name_of_your_aso_in_hivemodule_xml")
> stateManager.store("name_of_your_aso_in_hivemodule_xml", new_value)
>
> You have to do some casting to get things to work:
>
> ((MySessionObject) 
> stateManager.get("mySessionObject")).method_of_your_object()
>
> I do not know if this is the only / right way to do this. But thats 
> the way I do it in my services.
>
> Hope this helps,
> Gerald
>
> Mahmut Izci wrote:
>> Hi,
>>
>> I'm using several engine services in my application and
>> this services must get access to the application's session object.
>>
>> In hivemind.xml i defined a session object:
>>
>> <contribution configuration-id="tapestry.state.ApplicationObjects">
>>  <state-object name="mySessionObject" scope="session">
>>    <create-instance class="com.my.application.MySessionObject"/>
>>  </state-object> </contribution>
>>
>> Then I injected this into my service:
>>
>>  <service-point id="MyService" 
>> interface="org.apache.tapestry.engine.IEngineService">
>>    <invoke-factory>
>>      <construct class="com.my.application.MyService">
>>        <set-object property="exceptionReporter" 
>> value="infrastructure:requestExceptionReporter"/>
>>        <set-object property="response" value="infrastructure:response"/>
>>        <set-object property="linkFactory" 
>> value="infrastructure:linkFactory"/>
>>        <set-object property="request" value="infrastructure:request"/>
>>        /<set-object property="mySessionObject" 
>> value="app-property:mySessionObject"/>/
>>      </construct>
>>    </invoke-factory>
>>  </service-point>
>>
>> This session object is always not initialized and is null when I 
>> access it out of my service.
>> But when i inject the session object into the pages, it is initialized.
>>
>> How can an engine service get access to the session object?
>>
>> Thanks
>> Mahmut
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>


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


Re: injected session object in service always null

Posted by Gerald Schöffel <ta...@online.de>.
Hi Mahmut,

you could inject a ApplicationStateManager instead.

In your service:

private ApplicationStateManager stateManager ;
public ApplicationStateManager getStateManager() {
	return stateManager;
}
public void setStateManager(ApplicationStateManager stateManager) {
	this.stateManager = stateManager;
}

In hivemodule.xml:

<set-object property="stateManager" 
value="infrastructure:applicationStateManager"/>

To get access to your ASOs you can do the following:

stateManager.get("name_of_your_aso_in_hivemodule_xml")
stateManager.exists("name_of_your_aso_in_hivemodule_xml")
stateManager.store("name_of_your_aso_in_hivemodule_xml", new_value)

You have to do some casting to get things to work:

((MySessionObject) 
stateManager.get("mySessionObject")).method_of_your_object()

I do not know if this is the only / right way to do this. But thats the 
way I do it in my services.

Hope this helps,
Gerald

Mahmut Izci wrote:
> Hi,
> 
> I'm using several engine services in my application and
> this services must get access to the application's session object.
> 
> In hivemind.xml i defined a session object:
> 
> <contribution configuration-id="tapestry.state.ApplicationObjects">
>  <state-object name="mySessionObject" scope="session">
>    <create-instance class="com.my.application.MySessionObject"/>
>  </state-object> </contribution>
> 
> Then I injected this into my service:
> 
>  <service-point id="MyService" 
> interface="org.apache.tapestry.engine.IEngineService">
>    <invoke-factory>
>      <construct class="com.my.application.MyService">
>        <set-object property="exceptionReporter" 
> value="infrastructure:requestExceptionReporter"/>
>        <set-object property="response" value="infrastructure:response"/>
>        <set-object property="linkFactory" 
> value="infrastructure:linkFactory"/>
>        <set-object property="request" value="infrastructure:request"/>
>        /<set-object property="mySessionObject" 
> value="app-property:mySessionObject"/>/
>      </construct>
>    </invoke-factory>
>  </service-point>
> 
> This session object is always not initialized and is null when I access 
> it out of my service.
> But when i inject the session object into the pages, it is initialized.
> 
> How can an engine service get access to the session object?
> 
> Thanks
> Mahmut
> 


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