|
strutter@iharbeck.de
Updated 02.12.2008
|
StrutterStrutter is an open-source extention to the web application framework Apache Struts.
The configuration of Struts is done in a central XML configuation file
(struts-config.xml).
I experienced a lot of stupid and error prone copy-past tasks in my Struts development
cycle. I try to eliminate them with this project. Finding target for my With Strutter all configuration is stored within the action itself. It's a tag interface configuration concept. The configuration is done directly in the code and you can use the code completion features provided by your IDE. This eliminates typing of full qualified classname for Actions or ActionForms. Best of all, you don't need to switch legacy systems to the Strutter configuration concept completly. This extention can run in parallel with your existing struts configuration file. The core of this extention is Strutter Config it will handle the configuration. Strutter View is an optional part designed to extend the view of Struts MVC model.
It is the result of expiriences with the Struts tag library in a lot of projects.
Strutter View will automatically map the ActionForm attributes to the HTML form elements.
This is done by the
Strutter Extentions. Strutter provides entended versions of the default
Strutter ConfigFeaturesThe default conventions Benefits Example 1 (Dispatcher Pattern) /* The Action */
package example;
public class CustomerAction extends ActionDispatcher implements ConfigInterface
{
public void config(ActionConfig struts) {
struts.addForward("/customer_view.jsp");
}
...
}
/* Optional ActionForm Class (is found by classname matching) */
package example;
public class CustomerActionForm extends ActionForm
{
...
}
Example 2 (Multiple Action Pattern)/* The Action */
package example;
public class CustomerEditAction extends Action implements ConfigInterface
{
public void config(ActionConfig struts) {
struts.addForward("/customer_view.jsp");
}
}
/* Optional ActionForm Class */
package example;
public class CustomerEditActionForm extends ActionForm
{
...
}
or
public class CustomerActionForm extends ActionForm
{
...
}
Behind the scenes: Equivalent configuration (Dispatcher Pattern): <form-beans>
<form-bean name="CustomerActionForm" type="example.CustomerActionForm" />
</form-beans>
<action-mappings>
<action name="CustomerActionForm"
type="example.CustomerAction"
parameter="action"
scope="session"
path="/customer">
<forward name="view" path="/customer_view.jsp" />
</action>
</action-mappings>
All struts configuration is done dynamically during the startup of the struts plugin modules.
Installation <plug-in className="strutter.config.ActionPlugin" />That's it! The plugin searches your classpath for classes implementing ConfigInterface
ConfigZeroInterface
ConfigWSInterface
ConfigAutorunInterface
ConfigRemoteInterface
and will add the actions configuration programmatically on your applications startup.
Customize conventions
<plug-in className="strutter.config.ActionPlugin">
<set-property property="packageroot" value="action"/>
<set-property property="aliasaction" value="Action"/>
<set-property property="aliasform" value="ActionForm"/>
<set-property property="aliasview" value="view,list,update,create"/>
<set-property property="pathformat" value="{PATH}"/>
<set-property property="pathlower" value="0"/>
<set-property property="parameter" value="action"/>
<set-property property="scope" value="session"/>
<set-property property="views" value="views"/>
<set-property property="encoding" value="UTF-8"/>
<set-property property="viewer" value="1"/>
<set-property property="keepalive" value="1"/>
<set-property property="script" value="1"/>
<set-property property="template" value="1"/>
<set-property property="packageby" value="layer"/>
</plug-in>
Optional configuration struts.addForward("view", "/customer_view.jsp", [redirect:false]);
struts.addForward("/customer_view.jsp", [redirect:false]);
struts.addGlobalForward("view", "/customer_view.jsp", [redirect:false]);
struts.addGlobalForward("/customer_view.jsp", [redirect:false]);
struts.setPackageby(ActionConfig.PACKAGEBY_FEATURE);
struts.setForm(CustomerActionForm.class);
struts.setValidate(false);
struts.setInput("/customer_input.jsp");
struts.setParameter("action");
struts.setPath("/customer");
struts.setScope("session");
struts.setUnknown(false);
struts.setRoles("role1,role2");
Strutter ViewFeaturesaction handler
subber
subberconfirm
subbernowait
<form action="sample.do">
<select name="anrede">
<option id="anreden" />
</select>
<input type="text" name="firstname">
<input type="button" onclick="subber('update')" value="OK">
</form>
This example will map the ActionForm attribut anrede to
the select field anrede and firstname to the corresponding
form attribut.The option values can be added manual or will be read from the attribute anreden. It will try to locate it in session, request, actionform
(in this order).
Nothing special just simple HTML.
Error Handler <input type="text" name="firstname" error="behind">
The error message for each control is identified by the controls name. div / span <span type="text" id="label.name"/>Show resource message with id label.name:
<span type="resource" id="label.name"/>Show all messages as list: <div type="messages" />Show all errors as list: <div type="errors" />Show error with id firstname:
<div type="error" id="firstname"/>Disable processing a form element To disable processing of a single form element add the attribute nofill="nofill"
Installation <filter> <filter-name>strutterview</filter-name> <filter-class>strutter.view.PageFilter</filter-class> </filter> <filter-mapping> <filter-name>strutterview</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping>The rendered page will be processed by the filter. All INPUT,
SELECT, TEXTAREA are compared with the ActionForm and the tags value is
filled with the forms content of the corresponding attibute.
Strutter ExtentionsFeatures
ActionHelper
To add an
Subclass your
They still can be accessed via If the action has both Action Method with and without parameter. The one with parameter will have priority one.
Implement the
If you provide an
/* The Action */
package example;
public class CustomerAction extends PlainDispatchAction implements ConfigInterface, FormlessInterface
{
public void config(ActionConfig struts) {
struts.addForward("/customer_view.jsp");
}
public void reset() {
}
public ActionForward view() {
//...
ActionHelper.getRequest(); // ThreadLocal access to environment
//...
return ActionHelper.findForward("view");
}
String memo; // add some form attributes (They are handled Thread Safe)
//... getter and setter for "memo" ...
}
SQLHelperWebservice Autorun Remote TODO add documentation. |