Saturday, July 19, 2008

Shadow Services of Tapestry5 and example

The PropertyShadowBuilder service is used to allow a property of another service to be exposed as its own service.
TapestryModule.java has many shadow service example, like:


/**
* Builds a shadow of the RequestGlobals.request property. Note again that the shadow can be an ordinary singleton,
* even though RequestGlobals is perthread.
*/
public Request buildRequest()
{
return shadowBuilder.build(requestGlobals, "request", Request.class);
}

Then, we can inject Request service into page, and we will find class of request is $Request_11b3a7d984b built at runtime.

@Inject
private RequestGlobals requestGlobals;

@Inject
private Request request;

void pageLoaded(){
// class $Request_11b3a7d984b
System.out.println(request.getClass());
// class org.apache.tapestry5.internal.services.RequestImpl
System.out.println(requestGlobals.getRequest().getClass());
}

No comments :