Struts
Action classes
--------------
1) Action
2) DispatchAction
3) EventDispatchAction
4) LookupDispatchAction
5) MappingDispatchAction
6) DownloadAction
7) LocaleAction
8) ForwardAction
9) IncludeAction
10) SwitchAction
EventDispatchAction
-EventDispatchAction is
a sub class of DispatchAction
-Developer must derive
Action class from EventDispatchAction and must implement functions same as
DispatchAction class
-But in DispatchAction
the parameter attribute in struts-config.xml file contains request parameter
name (like "method"), each form submitting to struts must submit
request parameter name along with function want to be executed in
DispatchAction class as request parameter value
-In EventDispatchAction,
developer after implementing all the functions on Action class, the function
names must be registered in parameter attribute with comma seperator. This is
an indication that action class is registering all its functions as events in
s-c.xml file. JSP which are requesting to the same action path must use request
parameter name same as one of the event name registered in s-c.xml file. JSP those
which doesn't satisfy this condition will get JSP compilation error
-Configuring EDA sub
classes in s-c.xml
-During client request
If no event name is
specified as request parameter the default event will be taken
-Otherwise
LookupDispatchAction
--------------------
-Developer must sub
class Action class from LookupDispatchAction class and must implement one
function called getKeyMethodMap()
-The getKeyMethodMap()
function returns Map object
-The Map object contains
messagekey mapped to function name
-During client request
the form must submit request parameter name as "function" (this name
is config in s-c.xml file) and its value (request parameter value) must match
with one of the message value exist in ApplicationResources.properties file
-The moment
RequestProcessor receives client request, RP read req parameter value and
checks for the message value in AR.properties file, the corresponding message
key is retrieved
-RP instantiates Action
class, invokes getKeyMethodMap() function, lookupfor the message key in map
object, retrieves corresponding value from Map object and assumes that value as
business logic function in Action class
public class UserAction
extends LookupDispatchAction
{
protected Map
getKeyMethodMap()
{
Map m=new HashMap();
m.add("button.add","insert");
m.add("button.update","update");
return m;
}
insert(), update()
functions are as usual
}
ApplicationResources.properties
-------------------------------
button.add=Add User
button.update=Update
User
s-c.xml
-------
InsertUser.jsp
MappingDispatchAction
-The Action class must
be sub classing from MappingDispatchAction with the function same as before
-The same Action class
is mapped in s-c.xml file with different action paths and each such
configuration contains parameter name that holds function want to be executed
on Action class
UserInsert.jsp
UserUpdate.jsp
ForwardAction
-------------
-This Action is used to
connect to java web components & web documents through Struts framework
-Functioning is same as
RequestDispatcher.forward() operation in Servlets & tag of JSP
-When using this Action
class developer need not have to derive any class from ForwardAction
-When client request
action path, the path must be mapped to org.apache.struts.actions.ForwardAction
class in struts-config.xml file and its parameter could be pointing to JSP,
Servlet (old web components if any exist) and action path to another struts
module within the same web application
IncludeAction
-------------
Same as ForwardAction
except include() operation is used on JSP, Servlet and action paths of other
modules
LocaleAction
------------
-This action class is
used to change the localization of user
-When request comes to
action path of struts-config.xml file map the same to LocaleAction class
-This class implicitly
reads two request parameters "language" and "country" and
changes Locale object information @ session level
No comments:
Post a Comment