Integrate stecks with Struts (2)
I wanted to write down the learning process myself, but the result was translated, and it was not complete.
Well, it's just a translation.
Http://strecks.sourceforge.net/doc-actions.php
1. Actions
In stecks, the traditional strtus action is separated into two objects.
One is controller action and the other is an action bean.
1.1 controller actions
The idea behind controller action (also called Action Controller) is:
The general request processing logic can be abstract and reused by many actions.
For example, a simple crud web application usually uses three types of request processing logic:
@ Actioninterface (name = basicsubmitaction. Class)
Public class basicsubmitcontroller extends basebasiccontroller
{
@ Override
Protected viewadapter executeaction (Object actionbean, actioncontext context)
{
Basicsubmitaction action = (basicsubmitaction) actionbean;
Actionform form = context. getform ();
Httpservletrequest request = context. getrequest ();
Boolean canceled = false;
If (request. getattribute (globals. cancel_key )! = NULL)
{
Canceled = true;
}
If (Form instanceof bindingform &&! Canceled)
{
Action. prebind ();
Bindingform = (bindingform) form;
Bindingform. bindinwards ();
}
String result = canceled? Action. Cancel (): action.exe cute ();
Return getactionforward (context, result );
}
}
Stecks already has many built-in controllers that mimic dispatchaction, mappingdispatchaction, and lookupdispatchaction.
1.2 Action beans
After the request processing logic is extracted to the Controller action, the action bean only needs to process the specific business logic.
In stecks, Action bean will be configured into the struts-config.xml, just like the original strtus action.
When called for the first time, the annotation of this action bean is used to determine the controller, and the Controller instance will be created.
The controller integrates action and will be stored in the Action cache to process subsequent/concurrent requests.
After each request is received, the Controller will create a new action bean instance. The action controller is stateless and shared by multiple requests.
By default, Action bean and action controller correspond to the following:
Org. strecks. Action. basicaction org. strecks. Action. Basic. basiccontroller
Org. strecks. Action. basicformaction org. strecks. Action. Basic. basicformcontroller
Org. strecks. Action. basicsubmitaction org. strecks. Action. Basic. basicsubmitcontroller
Org. strecks. Action. basicdispatchaction org. strecks. Action. Basic. basicdispatchcontroller
Org. strecks. Action. navigableaction org. strecks. Action. navigable. navigablecontroller
Org. strecks. Action. navigableformaction org. strecks. Action. navigable. navigableformcontroller
Org. strecks. Action. navigablesubmitaction org. strecks. Action. navigable. navigablesubmitcontroller
Org. strecks. Action. navigabledispatchaction org. strecks. Action. navigable. navigabledispatchcontroller