[In brief]
* event-to-handler mapping now can be defined
in struts-config.xml file;
* Action class does not need to extend SelectAction
or DialogAction anymore to employ their dispatching
features.
Quick link: http://struts.sourceforge.net/strutsdialogs
Download:
https://sourceforge.net/project/showfiles.php?group_id=49385&package_id=154597
See details below.
[Externalized event mapping]
It is not necessary anymore to define event-to-handler mapping in
getMethodMap() method. While you can still use it, another option is
to define event mapping in the struts-config.xml file. This allows to
get a clean action mapping which defines all aspects of an action:
input event mapping, transfer mapping and output view mapping.
Externalized event-to-handler mapping is currently supported for new
syntax only, that is for <component> elements but not for <action>
elements.
For example, this action mapping defines a login dialog using standard
<action> element:
<action path = "/logindialog"
type = "net.acme.LoginDialog"
name = "loginform"
scope = "session"
validate = "false">
<forward name = "DIALOG-RELOAD" path = "/logindialog.do" redirect = "true"/>
<forward name = "USERHOME" path = "/userPage.do" redirect = "true"/>
<forward name = "DIALOG-VIEW" path = "/pages/login.jsp"/>
</action>
LoginDialog must also define an event-to-hanlder map like this:
protected Map getKeyMethodMap() {
Map map = new HashMap();
map.put("DIALOG_EVENT-INIT", "init");
map.put("DIALOG_EVENT-LOGIN", "login");
return map;
}
Now if you switch to new <component> syntax, you can define action
mapping along with event-to-handler map like this:
<component path = "/logindialog"
type = "net.acme.LoginDialog"
form = "loginform"
view = "/pages/login.jsp">
<event name = "DIALOG-EVENT-INIT" handler = "init"/>
<event name = "DIALOG-EVENT-LOGON" handler = "logon"/>
<transfer name = "USERHOME" path = "/userPage.do" />
</component>
[Using SelectAction and DialogAction as utility class]
If your action class has to extend another base class, you can use
SelectAction or DialogAction as utility class. Just declare a private
instance of either of these dispatching classes, define
event-to-handler map, and pass your custom action class as and
argument:
public class MyAction extends MyBaseAction implements ISelectAction {
private SelectAction selectAction = new SelectAction() {
protected Map getKeyMethodMap() {
Map map = new HashMap();
map.put(getInitKey() + "-ADD", "add");
map.put(getInitKey() + "-DELETE", "delete");
map.put(getInitKey() + "-LOGIN", "login");
map.put(getInitKey() + "-CANCEL", "cancel");
return map;
}
};
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
// ...
// Do your own stuff here
// ...
// Dispatch to handler, pass reference to self in the first argument.
return selectAction.execute(this, mapping, form, request, response);
}
...
}
Michael J.
--
Struts Dialogs: code-behind for Struts
http://struts.sourceforge.net/strutsdialogs
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]