Hi The reason the body is invoked is because there may be some logic which must be executed even if the call is not ajax. The worker only ensures that if javascript is disabled the call may still go through.
Regarding the return value, i modified the code to include cases you had pointed out. So this is the new worker package com.google.code.tapestryaddons.internal; import org.apache.tapestry5.model.MutableComponentModel; import org.apache.tapestry5.services.ClassTransformation; import org.apache.tapestry5.services.ComponentClassTransformWorker; import org.apache.tapestry5.services.ComponentMethodAdvice; import org.apache.tapestry5.services.ComponentMethodInvocation; import org.apache.tapestry5.services.Request; import org.apache.tapestry5.services.TransformMethod; import org.apache.tapestry5.services.TransformMethodSignature; import com.google.code.tapestryaddons.XHR; public class XHRWorker implements ComponentClassTransformWorker { private Request request; public XHRWorker(Request request){ this.request = request; } public void transform(ClassTransformation transformation, MutableComponentModel model) { for(final TransformMethod method: transformation.matchMethodsWithAnnotation(XHR.class)){ TransformMethodSignature signature = method.getSignature(); if(!"void".equals(signature.getReturnType())){ method.addAdvice(new ComponentMethodAdvice(){ public void advise(ComponentMethodInvocation invocation) { invocation.proceed(); Object result = invocation.getResult(); if(!request.isXHR()){ result = defaultForReturnType(result.getClass()); } invocation.overrideResult(result); } }); }else { throw new RuntimeException("XHR can be applied to non-void event handlers only"); } } } private Object defaultForReturnType(Class<?> returnType){ if (!returnType.isPrimitive()) return null; if (returnType.equals(boolean.class)) return false; return 0; } } I copied the method "defaultForReturnType()" from ChainBuilderImpl regards Taha On Mon, Jan 24, 2011 at 12:24 PM, Howard Lewis Ship <hls...@gmail.com>wrote: > I suppose this is useful, but what it does is to invoke the method > regardless of whether XHR is true or not, and then throw away the result. > > It probably should be: > > if (request.isXHR()) { > invocation.proceed(); > } > > I'm not sure what the else should be ... probably return null/0/false > (depending on the return type of the annotated method). > > > On Sun, Jan 23, 2011 at 4:42 AM, Thiago H. de Paula Figueiredo < > thiag...@gmail.com> wrote: > > > On Sun, 23 Jan 2011 10:01:17 -0200, Taha Hafeez < > tawus.tapes...@gmail.com> > > wrote: > > > > Thanks Thiago > >> > > > > :) > > > > You are absolutely right, in case of void it can throw an exception, i > >> will modify it and put it in my examples at > >> http://code.google.com/p/tapestry-addons/ > >> > > > > Why not Apache Extras (http://apache-extras.org/)? More info here: > > https://blogs.apache.org/comdev/entry/why_apache_extras. > > > > -- > > Thiago H. de Paula Figueiredo > > Independent Java, Apache Tapestry 5 and Hibernate consultant, developer, > > and instructor > > Owner, Ars Machina Tecnologia da Informação Ltda. > > http://www.arsmachina.com.br > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org > > For additional commands, e-mail: users-h...@tapestry.apache.org > > > > > > > -- > Howard M. Lewis Ship > > Creator of Apache Tapestry > > The source for Tapestry training, mentoring and support. Contact me to > learn > how I can get you up and productive in Tapestry fast! > > (971) 678-5210 > http://howardlewisship.com >