Struts 2 Annotations: @ParentPackage
June 11, 2014
@ParentPackage annotation in struts 2 is used to define different parent struts package. It is annotated on action class. @ParentPackage uses a name which can be declared in struts xml. In this page we will see code snippet how to use @ParentPackage in our struts 2 application. Find one use case to use @ParentPackage. Suppose we need to apply interceptor for different action class. To achieve it, define interceptor inside the package in struts xml as below.
<struts> <package name="myPackage" namespace="/" extends="struts-default"> <interceptors> </interceptors> </package> <constant name="struts.devMode" value="true" /> </struts>
import com.opensymphony.xwork2.ActionSupport; import org.apache.struts2.convention.annotation.ParentPackage; @ParentPackage(value ="myPackage") public class ResultAction extends ActionSupport{ public String execute() { System.out.println("ResultAction: Inside execute."); return SUCCESS; } }
For complete example refer the below URL.
Struts 2 Custom Interceptor Example Using @InterceptorRef Annotation