NOTE: This is outdated information that applies only to Tapestry 4.

How to inject an Application State Object (ASO) into a Tapestry service

Instead of injecting an ASO directly into a Tapestry service, we need to inject an Application{{`State}}Manager and use the ApplicationState`Manager to retrieve the desired ASO. Suppose you would like to inject the ASO message into the service asoService. The following piece of hivemodule.xml shows how it could be done.

 hivemodule.xml:

 <contribution configuration-id="tapestry.state.ApplicationObjects">
   <state-object name="message" scope="application">
   <create-instance class="man.aso.HelloMessage"/>
   </state-object>
</contribution>

       <!-- Inject ApplicationStateManger into service asoSerive -->
<service-point id="asoService" interface="org.apache.tapestry.engine.IEngineService">
    <invoke-factory>
      <construct class="service.ASOService">
        <set-object property="exceptionReporter" value="infrastructure:requestExceptionReporter"/>
        <set-object property="response" value="infrastructure:response"/>
        <set-object property="linkFactory" value="infrastructure:linkFactory"/>	
     <set-service property="appStateManager" 
                service-id="tapestry.state.ApplicationStateManager"/>
      </construct>
    </invoke-factory>
  </service-point>


In the .jave file of the Tapestry service asoService, add the setter/getter method for property app{{`State}}`Manager :

 private ApplicationStateManager appStateManager;
      public ApplicationStateManager getAppStateManager() {
		return appStateManager;
	}

	public void setAppStateManager(ApplicationStateManager appStateManager) {
		this.appStateManager = appStateManager;
	}

To access the ASO message in the asoService :

 HelloMessage message = (HelloMessage) getAppStateManager().get("message");
 
  • No labels