Em Tue, 22 Sep 2009 12:09:12 -0300, Joost Schouten (ml)
<joost...@jsportal.com> escreveu:
Hi,
Hi!
I am looking for a way to get a hold of all components Class'es on a
page while in a dispatcher. I want to know if any of the components on
the page are annotated with my custom @SecuredContent annotation but
have no clue how to figure out what components are loaded on a page when
I only have access to the page.
I don't know how you would get the component tree.
But, if the annotation was in a page, I would implement a
ComponentClassTransformer. This is an example that I hope it gives you a
clue:
public class TapestrySecurityWorker implements
ComponentClassTransformWorker {
public void transform(ClassTransformation transformation,
MutableComponentModel model) {
if (transformation.getAnnotation(NeedsLoggedInUser.class) !=
null) {
model.setMeta(TapestrySecurityConstants.NEEDS_LOGGED_IN_USER_METADATA_KEY,
"true");
}
}
}
The important trick here is the MutableComponentModel.setMeta() method.
Then, in a dispatcher, I can check the meta information:
String pageName = extractPageName(request);
if (pageName != null) {
final ComponentModel pageModel =
componentModelSource.getPageModel(pageName);
final String loggedInMetaValue =
pageModel.getMeta(TapestrySecurityConstants.NEEDS_LOGGED_IN_USER_METADATA_KEY);
...
}
private String extractPageName(Request request) {
String pageName = null;
final ComponentEventRequestParameters componentEventParameters =
linkEncoder.decodeComponentEventRequest(request);
if (componentEventParameters != null) {
pageName = componentEventParameters.getContainingPageName();
}
if (pageName == null) {
final PageRenderRequestParameters pageRenderParameters =
linkEncoder.decodePageRenderRequest(request);
if (pageRenderParameters != null) {
pageName = pageRenderParameters.getLogicalPageName();
}
}
return pageName;
}
linkEncoder is an instance of the ComponentEventLinkEncoder service.
--
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org