http://tapestry.javaeye.com/blog/36271
Tapestry中表单的提交有很多问题,刷新导致表单的重复提交、臭名昭著的dirty form warning、
显示不友好的URL等,这些都可以使用redirect-after-postpostredirectredirectredirectPagefriendlyUrlurl
要使用这个模式,不得不提到一个ILinkT4listener:
java 代码
- public ILink listenerMethod(Parameter parameter);
ILinkT4redirectILinkILinkLinkLinkLinkpage servicelinklinkexternal servicelinklink
java 代码
- @InjectObject("engine-service:page")
-
- public abstract IEngineService getPageService();
-
- public ILink getPageLink(String pageName) {
-
- return getPageService().getLink(false, pageName);
-
- }
-
-
-
- @InjectObject("engine-service:external")
-
- public abstract IEngineService getExternalService();
-
- public ILink getExternalLink(String pageName, Object[] parameters) {
-
- ExternalServiceParameter esp = new ExternalServiceParameter(pageName,
-
- parameters);
-
- return getExternalService().getLink(false, esp);
-
- }
将上述方法放入到你的项目中自定义的MyBasePage(继承Tapestry的BasePage)中,然后让你的
页面类继承MyBasePage,这样就可以使用上述方法了。
这样在页面提交时可以如下调用
java 代码
- public ILink onDelete(Long id){
-
-
-
-
-
-
-
- return getPageLink(getPageName());
-
- }
-
- 当然如果这个页面带参数,例如catgoryId=1,则代码如下:
-
- public ILink onDelete(Long id){
-
-
-
-
-
-
-
- return getExternalLink(getPageName(),new Object[]{categoryId});
-
-
- }
上述方式通过继承来实现方法调用,感觉不是很好,我们可以利用Tapestry的易扩展特性来扩展它,
首先想到的就是注释方式来注入,例如我想实现如下注入
java 代码
- @InjectPageLink(“Home“)
-
- Public abstract ILink getHomeLink();
-
-
-
- @InjectExternalLink(“Category“)
-
- Public abstract ILink getCategoryLink(Long categoryId);
这样即去掉了页面的继承,也显得比较直接。
首先是定义注释类
java 代码
- import java.lang.annotation.ElementType;
-
- import java.lang.annotation.Retention;
-
- import java.lang.annotation.RetentionPolicy;
-
- import java.lang.annotation.Target;
-
-
-
- @Target( { ElementType.METHOD })
-
- @Retention(RetentionPolicy.RUNTIME)
-
- public @interface InjectPageLink {
-
- String value();
-
- }
然后写注释的worker类
java 代码
- import java.lang.reflect.Method;
-
- import java.lang.reflect.Modifier;
-
-
-
- import org.apache.hivemind.ApplicationRuntimeException;
-
- import org.apache.hivemind.Location;
-
- import org.apache.hivemind.service.BodyBuilder;
-
- import org.apache.hivemind.service.MethodSignature;
-
- import org.apache.tapestry.annotations.AnnotationUtils;
-
- import org.apache.tapestry.annotations.MethodAnnotationEnhancementWorker;
-
- import org.apache.tapestry.engine.ILink;
-
- import org.apache.tapestry.enhance.EnhancementOperation;
-
- import org.apache.tapestry.spec.IComponentSpecification;
-
-
-
- public class InjectPageLinkAnnotationWorker implements
-
- MethodAnnotationEnhancementWorker {
-
-
-
- public void performEnhancement(EnhancementOperation op,
-
- IComponentSpecification spec, Method method, Location location) {
-
- if (!method.getReturnType().equals(ILink.class))
-
- throw new ApplicationRuntimeException(
-
- "InjectPage annotation must return ILink");
-
-
-
- InjectPageLink injectPageLink = method
-
- .getAnnotation(InjectPageLink.class);
-
-
-
- String pageName = injectPageLink.value();
-
-
-
- BodyBuilder builder = new BodyBuilder();
-
-
-
- builder.begin();
-
- builder
-
- .addln(
-
- "return getPage().getRequestCycle().getInfrastructure().getServiceMap().getService(
-
- org.apache.tapestry.Tapestry.PAGE_SERVICE).getLink(false,\"{0}\");",
-
- pageName);
-
-
-
- builder.end();
-
-
-
- op.addMethod(Modifier.PUBLIC, new MethodSignature(method), builder
-
- .toString(), location);
-
-
-
- if (isGetter(method))
-
- op.claimReadonlyProperty(AnnotationUtils.getPropertyName(method));
-
- }
-
-
-
- boolean isGetter(Method method) {
-
- return method.getName().startsWith("get")
-
- && method.getParameterTypes().length == 0;
-
- }
-
- }
External的同样两个类
java 代码
- import java.lang.annotation.ElementType;
-
- import java.lang.annotation.Retention;
-
- import java.lang.annotation.RetentionPolicy;
-
- import java.lang.annotation.Target;
-
-
-
- @Target( { ElementType.METHOD })
-
- @Retention(RetentionPolicy.RUNTIME)
-
- public @interface InjectExternalLink {
-
- String value();
-
- }
Work类
java 代码
- import java.lang.reflect.Method;
-
- import java.lang.reflect.Modifier;
-
-
-
- import org.apache.hivemind.ApplicationRuntimeException;
-
- import org.apache.hivemind.Location;
-
- import org.apache.hivemind.service.BodyBuilder;
-
- import org.apache.hivemind.service.MethodSignature;
-
- import org.apache.tapestry.Tapestry;
-
- import org.apache.tapestry.annotations.AnnotationUtils;
-
- import org.apache.tapestry.annotations.MethodAnnotationEnhancementWorker;
-
- import org.apache.tapestry.engine.ILink;
-
- import org.apache.tapestry.enhance.EnhancementOperation;
-
- import org.apache.tapestry.spec.IComponentSpecification;
-
-
-
- public class InjectExternalLinkAnnotationWorker implements
-
- MethodAnnotationEnhancementWorker {
-
-
-
- public void performEnhancement(EnhancementOperation op,
-
- IComponentSpecification spec, Method method, Location location) {
-
- if (!method.getReturnType().equals(ILink.class))
-
- throw new ApplicationRuntimeException(
-
- "injectExternalLink annotation must return ILink");
-
-
-
- InjectExternalLink injectExternalLink = method
-
- .getAnnotation(InjectExternalLink.class);
-
-
-
- String pageName = injectExternalLink.value();
-
-
-
- BodyBuilder builder = new BodyBuilder();
-
-
-
- builder.begin();
-
-
-
- Class[] parameterTypes = method.getParameterTypes();
-
- int paramCount = Tapestry.size(parameterTypes);
-
-
-
- if (paramCount > 0) {
-
- if (parameterTypes[0].isArray()) {
-
- builder
-
- .addln(
-
- "return getPage().getRequestCycle().getInfrastructure().getServiceMap().
-
- getService(org.apache.tapestry.Tapestry.EXTERNAL_SERVICE).getLink(false, new org.apache.tapestry.engine.ExternalServiceParameter(\"{0}\",$1));",
-
- pageName);
-
- } else {
-
- builder
-
- .addln(
-
- "java.lang.Object[] params = new java.lang.Object[{0}];",
-
- paramCount);
-
- for (int i = 0; i < paramCount; i++) {
-
- builder.add("params[{0}] = ", i);
-
-
-
- if (parameterTypes[i].isPrimitive())
-
- builder.add("($w) ");
-
-
-
-
-
-
-
- builder.addln("${0};", i + 1);
-
- }
-
- builder
-
- .addln(
-
- "return getPage().getRequestCycle().getInfrastructure().getServiceMap().getService(org.apache.tapestry.Tapestry.EXTERNAL_SERVICE).getLink(false, new org.apache.tapestry.engine.ExternalServiceParameter(\"{0}\",params));",
-
- pageName);
-
- }
-
- }
-
-
-
- builder.end();
-
-
-
- op.addMethod(Modifier.PUBLIC, new MethodSignature(method), builder
-
- .toString(), location);
-
-
-
- if (isGetter(method))
-
- op.claimReadonlyProperty(AnnotationUtils.getPropertyName(method));
-
- }
-
-
-
- boolean isGetter(Method method) {
-
-
-
-
-
- return method.getName().startsWith("get")
-
- && method.getParameterTypes().length == 0;
-
- }
-
- }
类写好了,然后就是贡献到Tapestry中
xml 代码
- <module id="your.model.annotation" version="1.0.0" package="your.package.annotations">
-
- <contribution configuration-id="tapestry.annotation.MethodWorkers">
-
- <worker annotation="InjectPageLink" object="instance:InjectPageLinkAnnotationWorker"/>
-
- <worker annotation="InjectExternalLink" object="instance:InjectExternalLinkAnnotationWorker"/>
-
- <!--</span-->contribution>
-
- <!--</span-->module>
好了将你的module放入项目hivemodule.Xml作为子module。
Ok,enjoy it!
Tapestry中表单的提交有很多问题,刷新导致表单的重复提交、臭名昭著的dirty form warning、 显示不友好的URL等,这些都可以使用redirect-after-postpostredirectredirectredirectPagefriendlyUrlurl 要使用这个模式,不得不提到一个ILinkT4listener: java 代码 - public ILink listenerMethod(Parameter parameter);
ILinkT4redirectILinkILinkLinkLinkLinkpage servicelinklinkexternal servicelinklink
java 代码 - @InjectObject("engine-service:page")
-
- public abstract IEngineService getPageService();
-
- public ILink getPageLink(String pageName) {
-
- return getPageService().getLink(false, pageName);
-
- }
-
-
-
- @InjectObject("engine-service:external")
-
- public abstract IEngineService getExternalService();
-
- public ILink getExternalLink(String pageName, Object[] parameters) {
-
- ExternalServiceParameter esp = new ExternalServiceParameter(pageName,
-
- parameters);
-
- return getExternalService().getLink(false, esp);
-
- }
将上述方法放入到你的项目中自定义的MyBasePage(继承Tapestry的BasePage)中,然后让你的 页面类继承MyBasePage,这样就可以使用上述方法了。 这样在页面提交时可以如下调用 java 代码 - public ILink onDelete(Long id){
-
-
-
-
-
-
-
- return getPageLink(getPageName());
-
- }
-
- 当然如果这个页面带参数,例如catgoryId=1,则代码如下:
-
- public ILink onDelete(Long id){
-
-
-
-
-
-
-
- return getExternalLink(getPageName(),new Object[]{categoryId});
-
-
- }
上述方式通过继承来实现方法调用,感觉不是很好,我们可以利用Tapestry的易扩展特性来扩展它, 首先想到的就是注释方式来注入,例如我想实现如下注入 java 代码 - @InjectPageLink(“Home“)
-
- Public abstract ILink getHomeLink();
-
-
-
- @InjectExternalLink(“Category“)
-
- Public abstract ILink getCategoryLink(Long categoryId);
这样即去掉了页面的继承,也显得比较直接。 首先是定义注释类 java 代码 - import java.lang.annotation.ElementType;
-
- import java.lang.annotation.Retention;
-
- import java.lang.annotation.RetentionPolicy;
-
- import java.lang.annotation.Target;
-
-
-
- @Target( { ElementType.METHOD })
-
- @Retention(RetentionPolicy.RUNTIME)
-
- public @interface InjectPageLink {
-
- String value();
-
- }
然后写注释的worker类
java 代码 - import java.lang.reflect.Method;
-
- import java.lang.reflect.Modifier;
-
-
-
- import org.apache.hivemind.ApplicationRuntimeException;
-
- import org.apache.hivemind.Location;
-
- import org.apache.hivemind.service.BodyBuilder;
-
- import org.apache.hivemind.service.MethodSignature;
-
- import org.apache.tapestry.annotations.AnnotationUtils;
-
- import org.apache.tapestry.annotations.MethodAnnotationEnhancementWorker;
-
- import org.apache.tapestry.engine.ILink;
-
- import org.apache.tapestry.enhance.EnhancementOperation;
-
- import org.apache.tapestry.spec.IComponentSpecification;
-
-
-
- public class InjectPageLinkAnnotationWorker implements
-
- MethodAnnotationEnhancementWorker {
-
-
-
- public void performEnhancement(EnhancementOperation op,
-
- IComponentSpecification spec, Method method, Location location) {
-
- if (!method.getReturnType().equals(ILink.class))
-
- throw new ApplicationRuntimeException(
-
- "InjectPage annotation must return ILink");
-
-
-
- InjectPageLink injectPageLink = method
-
- .getAnnotation(InjectPageLink.class);
-
-
-
- String pageName = injectPageLink.value();
-
-
-
- BodyBuilder builder = new BodyBuilder();
-
-
-
- builder.begin();
-
- builder
-
- .addln(
-
- "return getPage().getRequestCycle().getInfrastructure().getServiceMap().getService(
-
- org.apache.tapestry.Tapestry.PAGE_SERVICE).getLink(false,\"{0}\");",
-
- pageName);
-
-
-
- builder.end();
-
-
-
- op.addMethod(Modifier.PUBLIC, new MethodSignature(method), builder
-
- .toString(), location);
-
-
-
- if (isGetter(method))
-
- op.claimReadonlyProperty(AnnotationUtils.getPropertyName(method));
-
- }
-
-
-
- boolean isGetter(Method method) {
-
- return method.getName().startsWith("get")
-
- && method.getParameterTypes().length == 0;
-
- }
-
- }
External的同样两个类
java 代码 - import java.lang.annotation.ElementType;
-
- import java.lang.annotation.Retention;
-
- import java.lang.annotation.RetentionPolicy;
-
- import java.lang.annotation.Target;
-
-
-
- @Target( { ElementType.METHOD })
-
- @Retention(RetentionPolicy.RUNTIME)
-
- public @interface InjectExternalLink {
-
- String value();
-
- }
Work类
java 代码 - import java.lang.reflect.Method;
-
- import java.lang.reflect.Modifier;
-
-
-
- import org.apache.hivemind.ApplicationRuntimeException;
-
- import org.apache.hivemind.Location;
-
- import org.apache.hivemind.service.BodyBuilder;
-
- import org.apache.hivemind.service.MethodSignature;
-
- import org.apache.tapestry.Tapestry;
-
- import org.apache.tapestry.annotations.AnnotationUtils;
-
- import org.apache.tapestry.annotations.MethodAnnotationEnhancementWorker;
-
- import org.apache.tapestry.engine.ILink;
-
- import org.apache.tapestry.enhance.EnhancementOperation;
-
- import org.apache.tapestry.spec.IComponentSpecification;
-
-
-
- public class InjectExternalLinkAnnotationWorker implements
-
- MethodAnnotationEnhancementWorker {
-
-
-
- public void performEnhancement(EnhancementOperation op,
-
- IComponentSpecification spec, Method method, Location location) {
-
- if (!method.getReturnType().equals(ILink.class))
-
- throw new ApplicationRuntimeException(
-
- "injectExternalLink annotation must return ILink");
-
-
-
- InjectExternalLink injectExternalLink = method
-
- .getAnnotation(InjectExternalLink.class);
-
-
-
- String pageName = injectExternalLink.value();
-
-
-
- BodyBuilder builder = new BodyBuilder();
-
-
-
- builder.begin();
-
-
-
- Class[] parameterTypes = method.getParameterTypes();
-
- int paramCount = Tapestry.size(parameterTypes);
-
-
-
- if (paramCount > 0) {
-
- if (parameterTypes[0].isArray()) {
-
- builder
-
- .addln(
-
- "return getPage().getRequestCycle().getInfrastructure().getServiceMap().
-
- getService(org.apache.tapestry.Tapestry.EXTERNAL_SERVICE).getLink(false, new org.apache.tapestry.engine.ExternalServiceParameter(\"{0}\",$1));",
-
- pageName);
-
- } else {
-
- builder
-
- .addln(
-
- "java.lang.Object[] params = new java.lang.Object[{0}];",
-
- paramCount);
-
- for (int i = 0; i < paramCount; i++) {
-
- builder.add("params[{0}] = ", i);
-
-
-
- if (parameterTypes[i].isPrimitive())
-
- builder.add("($w) ");
-
-
-
-
-
-
-
- builder.addln("${0};", i + 1);
-
- }
-
- builder
-
- .addln(
-
- "return getPage().getRequestCycle().getInfrastructure().getServiceMap().getService(org.apache.tapestry.Tapestry.EXTERNAL_SERVICE).getLink(false, new org.apache.tapestry.engine.ExternalServiceParameter(\"{0}\",params));",
-
- pageName);
-
- }
-
- }
-
-
-
- builder.end();
-
-
-
- op.addMethod(Modifier.PUBLIC, new MethodSignature(method), builder
-
- .toString(), location);
-
-
-
- if (isGetter(method))
-
- op.claimReadonlyProperty(AnnotationUtils.getPropertyName(method));
-
- }
-
-
-
- boolean isGetter(Method method) {
-
-
-
-
-
- return method.getName().startsWith("get")
-
- && method.getParameterTypes().length == 0;
-
- }
-
- }
类写好了,然后就是贡献到Tapestry中 xml 代码 - <module id="your.model.annotation" version="1.0.0" package="your.package.annotations">
-
- <contribution configuration-id="tapestry.annotation.MethodWorkers">
-
- <worker annotation="InjectPageLink" object="instance:InjectPageLinkAnnotationWorker"/>
-
- <worker annotation="InjectExternalLink" object="instance:InjectExternalLinkAnnotationWorker"/>
-
- <!--</span-->contribution>
-
- <!--</span-->module>
好了将你的module放入项目hivemodule.Xml作为子module。 Ok,enjoy it!
|
是呀,tapestry的经典处理流程就是get page->set state->active
active调用的是forward方法,就是当前页面的实际页面与url上指示的页面不相符,这也无可厚非。tapestry如果真的要完全的OO的话,屏蔽URL上的处理是必须的。
取得ILink来redirect的一个好处是可以防止form提交后refresh。 |
Tapestry中表单的提交有很多问题,刷新导致表单的重复提交、臭名昭著的dirty form warning、
显示不友好的URL等,这些都可以使用redirect-after-postpostredirectredirectredirectPagefriendlyUrlurl
要使用这个模式,不得不提到一个ILinkT4listener:
java 代码
- public ILink listenerMethod(Parameter parameter);
ILinkT4redirectILinkILinkLinkLinkLinkpage servicelinklinkexternal servicelinklink
java 代码
- @InjectObject("engine-service:page")
-
- public abstract IEngineService getPageService();
-
- public ILink getPageLink(String pageName) {
-
- return getPageService().getLink(false, pageName);
-
- }
-
-
-
- @InjectObject("engine-service:external")
-
- public abstract IEngineService getExternalService();
-
- public ILink getExternalLink(String pageName, Object[] parameters) {
-
- ExternalServiceParameter esp = new ExternalServiceParameter(pageName,
-
- parameters);
-
- return getExternalService().getLink(false, esp);
-
- }
将上述方法放入到你的项目中自定义的MyBasePage(继承Tapestry的BasePage)中,然后让你的
页面类继承MyBasePage,这样就可以使用上述方法了。
这样在页面提交时可以如下调用
java 代码
- public ILink onDelete(Long id){
-
-
-
-
-
-
-
- return getPageLink(getPageName());
-
- }
-
- 当然如果这个页面带参数,例如catgoryId=1,则代码如下:
-
- public ILink onDelete(Long id){
-
-
-
-
-
-
-
- return getExternalLink(getPageName(),new Object[]{categoryId});
-
-
- }
上述方式通过继承来实现方法调用,感觉不是很好,我们可以利用Tapestry的易扩展特性来扩展它,
首先想到的就是注释方式来注入,例如我想实现如下注入
java 代码
- @InjectPageLink(“Home“)
-
- Public abstract ILink getHomeLink();
-
-
-
- @InjectExternalLink(“Category“)
-
- Public abstract ILink getCategoryLink(Long categoryId);
这样即去掉了页面的继承,也显得比较直接。
首先是定义注释类
java 代码
- import java.lang.annotation.ElementType;
-
- import java.lang.annotation.Retention;
-
- import java.lang.annotation.RetentionPolicy;
-
- import java.lang.annotation.Target;
-
-
-
- @Target( { ElementType.METHOD })
-
- @Retention(RetentionPolicy.RUNTIME)
-
- public @interface InjectPageLink {
-
- String value();
-
- }
然后写注释的worker类
java 代码
- import java.lang.reflect.Method;
-
- import java.lang.reflect.Modifier;
-
-
-
- import org.apache.hivemind.ApplicationRuntimeException;
-
- import org.apache.hivemind.Location;
-
- import org.apache.hivemind.service.BodyBuilder;
-
- import org.apache.hivemind.service.MethodSignature;
-
- import org.apache.tapestry.annotations.AnnotationUtils;
-
- import org.apache.tapestry.annotations.MethodAnnotationEnhancementWorker;
-
- import org.apache.tapestry.engine.ILink;
-
- import org.apache.tapestry.enhance.EnhancementOperation;
-
- import org.apache.tapestry.spec.IComponentSpecification;
-
-
-
- public class InjectPageLinkAnnotationWorker implements
-
- MethodAnnotationEnhancementWorker {
-
-
-
- public void performEnhancement(EnhancementOperation op,
-
- IComponentSpecification spec, Method method, Location location) {
-
- if (!method.getReturnType().equals(ILink.class))
-
- throw new ApplicationRuntimeException(
-
- "InjectPage annotation must return ILink");
-
-
-
- InjectPageLink injectPageLink = method
-
- .getAnnotation(InjectPageLink.class);
-
-
-
- String pageName = injectPageLink.value();
-
-
-
- BodyBuilder builder = new BodyBuilder();
-
-
-
- builder.begin();
-
- builder
-
- .addln(
-
- "return getPage().getRequestCycle().getInfrastructure().getServiceMap().getService(
-
- org.apache.tapestry.Tapestry.PAGE_SERVICE).getLink(false,\"{0}\");",
-
- pageName);
-
-
-
- builder.end();
-
-
-
- op.addMethod(Modifier.PUBLIC, new MethodSignature(method), builder
-
- .toString(), location);
-
-
-
- if (isGetter(method))
-
- op.claimReadonlyProperty(AnnotationUtils.getPropertyName(method));
-
- }
-
-
-
- boolean isGetter(Method method) {
-
- return method.getName().startsWith("get")
-
- && method.getParameterTypes().length == 0;
-
- }
-
- }
External的同样两个类
java 代码
- import java.lang.annotation.ElementType;
-
- import java.lang.annotation.Retention;
-
- import java.lang.annotation.RetentionPolicy;
-
- import java.lang.annotation.Target;
-
-
-
- @Target( { ElementType.METHOD })
-
- @Retention(RetentionPolicy.RUNTIME)
-
- public @interface InjectExternalLink {
-
- String value();
-
- }
Work类
java 代码
- import java.lang.reflect.Method;
-
- import java.lang.reflect.Modifier;
-
-
-
- import org.apache.hivemind.ApplicationRuntimeException;
-
- import org.apache.hivemind.Location;
-
- import org.apache.hivemind.service.BodyBuilder;
-
- import org.apache.hivemind.service.MethodSignature;
-
- import org.apache.tapestry.Tapestry;
-
- import org.apache.tapestry.annotations.AnnotationUtils;
-
- import org.apache.tapestry.annotations.MethodAnnotationEnhancementWorker;
-
- import org.apache.tapestry.engine.ILink;
-
- import org.apache.tapestry.enhance.EnhancementOperation;
-
- import org.apache.tapestry.spec.IComponentSpecification;
-
-
-
- public class InjectExternalLinkAnnotationWorker implements
-
- MethodAnnotationEnhancementWorker {
-
-
-
- public void performEnhancement(EnhancementOperation op,
-
- IComponentSpecification spec, Method method, Location location) {
-
- if (!method.getReturnType().equals(ILink.class))
-
- throw new ApplicationRuntimeException(
-
- "injectExternalLink annotation must return ILink");
-
-
-
- InjectExternalLink injectExternalLink = method
-
- .getAnnotation(InjectExternalLink.class);
-
-
-
- String pageName = injectExternalLink.value();
-
-
-
- BodyBuilder builder = new BodyBuilder();
-
-
-
- builder.begin();
-
-
-
- Class[] parameterTypes = method.getParameterTypes();
-
- int paramCount = Tapestry.size(parameterTypes);
-
-
-
- if (paramCount > 0) {
-
- if (parameterTypes[0].isArray()) {
-
- builder
-
- .addln(
-
- "return getPage().getRequestCycle().getInfrastructure().getServiceMap().
-
- getService(org.apache.tapestry.Tapestry.EXTERNAL_SERVICE).getLink(false, new org.apache.tapestry.engine.ExternalServiceParameter(\"{0}\",$1));",
-
- pageName);
-
- } else {
-
- builder
-
- .addln(
-
- "java.lang.Object[] params = new java.lang.Object[{0}];",
-
- paramCount);
-
- for (int i = 0; i < paramCount; i++) {
-
- builder.add("params[{0}] = ", i);
-
-
-
- if (parameterTypes[i].isPrimitive())
-
- builder.add("($w) ");
-
-
-
-
-
-
-
- builder.addln("${0};", i + 1);
-
- }
-
- builder
-
- .addln(
-
- "return getPage().getRequestCycle().getInfrastructure().getServiceMap().getService(org.apache.tapestry.Tapestry.EXTERNAL_SERVICE).getLink(false, new org.apache.tapestry.engine.ExternalServiceParameter(\"{0}\",params));",
-
- pageName);
-
- }
-
- }
-
-
-
- builder.end();
-
-
-
- op.addMethod(Modifier.PUBLIC, new MethodSignature(method), builder
-
- .toString(), location);
-
-
-
- if (isGetter(method))
-
- op.claimReadonlyProperty(AnnotationUtils.getPropertyName(method));
-
- }
-
-
-
- boolean isGetter(Method method) {
-
-
-
-
-
- return method.getName().startsWith("get")
-
- && method.getParameterTypes().length == 0;
-
- }
-
- }
类写好了,然后就是贡献到Tapestry中
xml 代码
- <module id="your.model.annotation" version="1.0.0" package="your.package.annotations">
-
- <contribution configuration-id="tapestry.annotation.MethodWorkers">
-
- <worker annotation="InjectPageLink" object="instance:InjectPageLinkAnnotationWorker"/>
-
- <worker annotation="InjectExternalLink" object="instance:InjectExternalLinkAnnotationWorker"/>
-
- <contribution>
-
- <module>
好了将你的module放入项目hivemodule.Xml作为子module。
Ok,enjoy it!