I found that it's very easy to forget some details about how Struts 2 works, if I don't do Web development everyday or use it on daily basis.
Here are some notes about Struts 2 Action that is worth to remember.
- Bundling actions into packages.
This is about configurations in struts.xml file, including package name(a logical name by which you can reference the package), namespace(used to generate the URL namespace to which the actions of these packages are mapped), and extends (most of the useful interceptors can be found in the struts-default package, e.g. file upload, params, workflow, etc.).
- Instead of implementing Action interface, extend ActionSupport class is what one needs to do to get an action. It implements other interfaces which provide basic functions. (e.g. validate request data, use resource bundles for reading property file, etc)
- Two approaches for transferring data onto objects: 1. Object-backed JavaBeans properties. 2. ModelDriven actions
Here is a good diagram from VaanNila Struts 2 tutorial.
<pre><code> String foo = "bar"; </code></pre>