|
Adding Spice to Struts
The Road Map…
Our Solution 2 demands some manipulation of the Struts framework
components. Hence, we decided to trace how the declarative form
bean configuration is mapped to the form bean objects within the
Struts layer. We have done a dissection of the Struts and the
following facts were laid before us.
-
Struts uses the Commons Digester component of the configuration files.
-
The Commons Digester component relies on a set of rules to be
passed to it in order to parse the configuration file. Struts
passes a ConfigRuleSet object to the Digester component.
-
The ConfigRuleSet object contains all the parsing rules.
-
For the form bean configuration Struts uses a class called
FormBeanConfig.
-
The framework initialises any particular form bean class by
calling its initialize() method. Within the initialize() method
each particular FormBean class gets hold of its own
FormBeanConfig object, obtains all the properties and….
-
Dynamic Action Form classes(DynaActionForm etc.) gets all the
properties from the FormBeanConfig object and puts them in a
Map.
These facts again opened at least two possible solutions.
But we soon realized the potential risks associated with each of them.
Working Out the Kinks
Now we pretty much have an idea of what to do. Our first
reaction was to come up with a form-bean declaration like this:
<form-bean
name="someForm" type="org.apache.struts.action.DynaActionForm"
includes=”anotherForm”>
In this mode of declaration, the form-bean "someForm" will
include all the properties declared in the form-bean
"anotherForm". This is exactly what we wanted. However, we
raised that in order to implement this solution we need to do
the followings:
-
The ConfigRuleSet class already declares rules by which we can
capture any attribute defined for the <form-bean> tag.
This is good news.
-
However, The Ruleset Also Defines That The Defined Attributes
Must Correspond To The Instance Variables Of The Formbeanconfig
Class. For Example, There Are Two Attributes "Name" And Type" In
The ≪Form-Bean≫ Tag And The Formbeanconfig Class Also
Defines Two Instance Variables Called "Name" And "Type". The
Digester Component Sets The Values Of These Instance Variables
To The Attribute Value Specified In The Configuration File By
Invoking The Corresponding Set() Methods In The Formbeanconfig
Class.
-
Thus, to accommodate another attribute for the <form-bean>
tag, we need to extend the FormBeanConfig class.
-
Moreover, there is no easy way to attach a custom FormBeanConfig
class to the framework. The only alternative is to create a new
RuleSet class, which defines the rules for parsing the <form-
bean> definition by specifying the alternative FormBeanConfig
class.
-
Thus, we need to create a new RuleSet class.
-
Additionally, we raised that in the initialization process of the
form bean, we need to read all the properties of another form
bean defined in the "includes" attribute and put them into the
map of the original form bean. For example, the initialization
process should put all the properties of the "anotherForm" form
bean in the Map of the form bean "someForm".
-
In order to achieve this, we need to extend the existing
DynaActionForm and override the initialize() method to do the
job.
By carefully weighing the work involved, we decided that it is
certainly an overkill to create a new FormBeanConfig class and a
new RuleSet class. But in all the cases, we need to come up with
a new FormBean class to override the initialize() method.
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.
|