Overview
Packages are a way to group Actions, Results, Result Types, Interceptors and Stacks actions, results, result types, interceptors, and interceptor-stacks into a logical configuration unit that shares a common configuration. Packages . Conceptually, packages are similiar to objects in that they can be extended and have individual parts that can be overridden by "sub" packages.
Packages
The package element has one required attribute, "name
", which acts as the key for later reference to this the package. The "extends
" attribute is optional and allows one package to inherit the configuration of one or more previous packages - including all interceptor, interceptor-stack, and action configurations.
Note that the configuration file is processed sequentially down the document, so the package referenced by an "extends" should be defined above the package which extends it.
The "optional abstract
" optional attribute allows you to make a package abstract, which will allow you to extend from it without the action configurations defined in the abstract package actually being available at runtime attribute creates a base package that can omit the action configuration.
Attribute | Required | Description |
---|---|---|
name | yes | key to for other packages to reference |
extends | no | inherits package behavior of the package it extends |
namespace | no | |
abstract | no | declares package to be abstract (no action configurations required in package) |
...
Simple usage
Code Block | ||
---|---|---|
| ||
<struts> <package name="baremployee" extends="webworkstruts-default" namespace="/foo/baremployee"> <interceptors> <interceptor-stack<default-interceptor-ref name="barDefaultStackcrudStack"/> <action <interceptor-ref name="debugStack"/>name="list" method="list" <interceptor-ref name="defaultStack"/class="org.apache.struts2.showcase.action.EmployeeAction" > </interceptor-stack> </interceptors> <action name="Bar" class="com.opensymphony.xwork.SimpleAction"> <result>/empmanager/listEmployees.jsp</result> <interceptor-ref name="barDefaultStackbasicStack"/> </action> <action name="TestInterceptorParamInheritanceedit-*" class="com.opensymphony.xwork.SimpleActionorg.apache.struts2.showcase.action.EmployeeAction"> <interceptor-ref <param name="test"> <param name="expectedFoo">expectedFoo<empId">{1}</param> </interceptor-ref> </action> <action name="TestInterceptorParamInehritanceOverride" class="com.opensymphony.xwork.SimpleAction"> <result>/empmanager/editEmployee.jsp</result> <interceptor-ref name="testcrudStack"> <param name="foovalidation.excludeMethods">foo123<>execute</param> <param name="expectedFoo">foo123</param> </interceptor-ref> </action> </package> <package<action name="abstractPackagesave" namespacemethod="/abstract" abstract="true">save" <action name="test" class="com.opensymphony.xwork.SimpleAction"/org.apache.struts2.showcase.action.EmployeeAction" > </package> <package<result name="nonAbstractPackage" extends="abstractPackage" namespace="/nonAbstract"/> <package name="baz" extends="default" namespace="baz"> <action name="commandTest" class="com.opensymphony.xwork.SimpleAction"> <param name="foo">123</param> input">/empmanager/editEmployee.jsp</result> <result name="error" type="chain"> <param name="actionName">bar</param> </result> <interceptor-ref name="static-params"/> redirect">edit-${currentEmployee.empId}.action</result> </action> <action name="myCommand" class="com.opensymphony.xwork.SimpleAction"delete" method="commandMethoddelete"> <param name="bar">456</param>class="org.apache.struts2.showcase.action.EmployeeAction" > <result name="success" type="chain"> <param name="actionName">foo</param> <error">/empmanager/editEmployee.jsp</result> <interceptor-ref name<result type="logger"/> redirect">edit-${currentEmployee.empId}.action</result> </action> </package> </struts> |
Inherit from more than one package
Code Block | ||
---|---|---|
| ||
<struts> <package name="multipleInheritanceemployee" extends="struts-default,abstractPackage,bar json-default" namespace="multipleInheritance/employee"> <action name="list" method="testMultipleInheritancelist" class="com.opensymphony.xwork.SimpleAction"> org.apache.struts2.showcase.action.EmployeeAction" > <result>/empmanager/listEmployees.jsp</result> <result name="success" <result type="chainjson"> <param name="actionNameroot">foo<>employees</param> </result> <interceptor-ref name="barDefaultStack"/> </action> </package></action> </package> </struts> |