You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by jpoder <ja...@thermofisher.com> on 2012/06/04 15:48:45 UTC
Re: @XHR : isXHR shortcut
Hi,
I'm looking for a general solution to avoid constructs like this in all my
event handlers:
Object onMyAjaxEventHandler(){
do_some_processing();
if(request.isXHR()){
return zone.getBody();
}
return null;
}
Taha's @XHR annotation is a step in the right direction, but finding myself
adding that to every single method that returns zone.getBody() makes me
think that getBody() could make the distinction internally.
Now, I realize that this is quite intrusive to the Zone component, but it
does keep my event handler code a lot cleaner!
I experimentally created the component transformer shown below, which does
the work for me.
Would you advice against and/or could you suggest a better abstraction for
doing this?
Also, should I call invocation.proceed() even in the non-XHR case to ensure
other method advices be run?
Thanks for your input!
Best regards,
Jacob
--
View this message in context: http://tapestry.1045711.n5.nabble.com/XHR-isXHR-shortcut-tp3353416p5713607.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
RE: @XHR : isXHR shortcut
Posted by "Poder, Jacob" <ja...@thermofisher.com>.
Hmm, apparently the code was filtered out but is included here:
http://tapestry.1045711.n5.nabble.com/XHR-isXHR-shortcut-tp3353416p5713607.html
I'll try posting it again:
// Code begin
public class ZoneWorker implements ComponentClassTransformWorker2 {
protected Request request;
public ZoneWorker(Request request) {
this.request = request;
}
public void transform(PlasticClass plasticClass, TransformationSupport support, MutableComponentModel model) {
// Find Zone's getBody method
PlasticMethod getBody = null;
if (plasticClass.getClassName().equals(Zone.class.getName())) {
for (PlasticMethod method : plasticClass.getMethods()) {
if (method.getDescription().methodName.toLowerCase().equals("getbody")) {
getBody = method;
break;
}
}
getBody.addAdvice(new MethodAdvice() {
public void advise(MethodInvocation invocation) {
if(request.isXHR()) {
// Proceed to Zone's getBody method
invocation.proceed();
} else {
// Override to return null and trigger full page render
invocation.setReturnValue(null);
}
}
});
}
}
}
// Code end
Best regards,
Jacob
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org