Another way to get the annotation associated with the executed action is private static boolean isAnnotationPresent(ActionInvocation actionInvocation, Class<? extends Annotation> annotationClass) { return getMethodFromInvocation(actionInvocation).isAnnotationPresent( annotationClass);
} private static Method getMethodFromInvocation(ActionInvocation actionInvocation) { Method method; try { method = actionInvocation.getAction().getClass() .getMethod(actionInvocation.getProxy().getMethod()); // should never happen because struts would have failed before this method call //if the method didn't exist } catch (SecurityException e) { throw new RuntimeException(e); } catch (NoSuchMethodException e) { throw new RuntimeException(e); } return method; } Antonios On 7 June 2014 05:57, Alireza Fattahi <afatt...@yahoo.com.invalid> wrote: > Thanks! > A complete code sample at: > > > http://stackoverflow.com/questions/24021534/struts-2-get-custom-action-anotation-in-interceptors > > > > ~Regards, > ~~Alireza Fattahi > > > On Wednesday, 4 June 2014, 12:22, Lukasz Lenart <lukaszlen...@apache.org> > wrote: > > > > Take a look on com.opensymphony.xwork2.util.AnnotationUtils > > > 2014-06-03 19:37 GMT+02:00 Alireza Fattahi <afatt...@yahoo.com.invalid>: > > Consider below action class with three action mappings. Two of them are > annotated with a custom annotation `@AjaxAction` > > > > public class MyAction extends ActionSupport{ > > > > @Action("action1") > > @AjaxAction //My custom anotation > > public String action1(){ > > } > > > > @Action("action2") > > public String action2(){ > > } > > > > @Action("action3") > > @AjaxAction //My custom anotation > > public String action3(){ > > } > > } > > > > > > In an interceptor I want to access the `@AjaxAction` annotation. Is > there any built in support for this?! > > > > If not can I shall read the action name with > `ActionContext.getContext().getName();` and save a list of `ajaxAction` > names in interceptor as an array and compare action name with this array! > any better way?! > > > > private static final String[] AJAX_ACTIONS = new String[] > {"action1", "action3"} > > > > //in interceptor > > String actionName = ActionContext.getContext().getName(); > > if (Arrays.asList(AJAX_ACTIONS).contains(actionName)) { > > // do something > > } > > > > > > ~Regards, > > ~~Alireza Fattahi > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org