In this last step, you will see how to configure Struts2 packages.
On step 6, we saw how to get parameters in an action: we need to as "params" interceptor.
But we saw how to add this interceptor on only one action. With struts2 packages, you will be able to define properties (such as interceptor-refs) that are common to all actions in that package.
Furthermore, you will be able to split your application in several path segments (each struts package defines a namespace).
In this tutorial, we will split actions in two struts packages:
First of all, go back to Hello World action, and remove all previously defined interceptors. We will now define interceptors at package level.
Open struts 2 tab, on editor's bottom:
This panel is organized in two parts:
Open tree, and right click on "packages" node:
Click on the "Add" menu.
Then fill all fields. We want to create a package that inherits alveole-defaults package, named HelloWorld, having path "hw":
On the newly created package, open tree nodes:
Then right-click on "interceptors" node, and click "Add stack". Name it "interceptorstack".
Deploy newly created interceptor stack tree node.
Then, on helloworldstack tree node, right-click and add a new interceptor reference.
The interceptor to reference, is "params":
Then click OK. The stack is created, we need to set it as default. Right-click on HelloWorld package:
Choose "set default interceptor". On the right panel, then select helloworldstack.
Then click OK. Package is configured.
Now package is defined, we must assign its actions. There are two ways assigning actions to packages: either assign action's package directly in action's edition panel, or assign it on tree package (then all descending actions will be assigned to struts2 package).
Go back on tree, and select Hello World package:
Then open "struts2" tab and select helloworld struts2 package:
Then click OK. HelloWorld tree package is then assigned to HelloWorld struts 2 package.