Caros,
Procurei mas não encontrei nada concreto sobre isso, então resolvi postar, vamos lá.
Action
package br.com.teste.action;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.Result;
import com.opensymphony.xwork2.ActionSupport;
public class HelloWorldAction extends ActionSupport {
private static final long serialVersionUID = -8536563318993968542L;
public static final String MESSAGE = "Struts rodando!";
private String message;
@Action(value = "/welcome", results = { @Result(name = "success", location = "/HelloWorld.jsp") }, interceptorRefs = { @InterceptorRef("loginStack")})
public String execute() {
setMessage(MESSAGE);
return SUCCESS;
}
/**
* @param message
* the message to set
*/
public void setMessage(String message) {
this.message = message;
}
/**
* @return the message
*/
public String getMessage() {
return message;
}
}
Interceptor
package br.com.teste.action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
public class LoginCheckInterceptor implements Interceptor {
/**
*
*/
private static final long serialVersionUID = -5361082118609994164L;
@Override
public void destroy() {
// TODO Auto-generated method stub
}
@Override
public void init() {
// TODO Auto-generated method stub
}
@Override
public String intercept(ActionInvocation invocation) throws Exception {
boolean b = false;
if (!b) {
return invocation.invoke();
} else {
return "LoginFalha";
}
}
}
Primeiro gostaria de saber se, mesmo usando annotations, preciso declarar o interceptor no struts.xml?
Independente do caso acima, eu já tentei das duas formas, mas sempre obtenho a mensagem:
Unable to find interceptor class referenced by ref-name LoginCheckInterceptor - [unknown location]
struts.xml
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="default" extends="struts-default">
<interceptors>
<interceptor name="loginInterceptor" class="br.com.teste.action.LoginCheckInterceptor"></interceptor>
<interceptor-stack name="loginStack">
<interceptor-ref name="loginInterceptor"></interceptor-ref>
</interceptor-stack>
</interceptors>
</package>
</struts>
Será que alguém poderia me dizer onde estou errando? Ou então postar algum exemplo funcional de interceptor com annotations?
Desde já obrigado.