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

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

 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 appStateManager :

 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");

InjectASOIntoService (last edited 2011-01-02 02:28:25 by BobHarner)