Martin,

I'm new to the Struts project, but we're about to migrate a massive codebase to
JSP/Struts and have identified this as a sore spot.  Basically we need a
rules-based engine for populating/generating forms.  In addition, many of the
form fields are directly correlated with our forms, and it's painful to manually
copy the fields from forms to beans.

We're preparing to grow our own, but here are a few of the ideas we're planing
on implementing.  Caveat: we're assuming everything is enforced at runtime -
it's similar to, but a step beyond, David Winterfeldt's work.

Basic Features:

1) The base action form is a Map (a hashtable*). At request-time, the proper
definition is retrieved and the map is populated based on its definition.

Form definitions will look something like this:
<form id="Foo">
  <field name="people" type="Integer" required="true">
  <field name="adate" type="Date" required="true">
...


2) The popuulated map is validated against the definition - types are enforced
by input validators which are defined a separate section of the XML definition:

<mapper type="Date" class="com.xyz.mapper.Date">
<mapper type="Integer" class="com.xyz.mapper.Integer">
...

3) At the appropriate point in the action, the form can be mapped to/from a data
bean, again based on the definition:

<form>
...
<mapping class="com.xyz.entity.Foo">
  <map property="people">
  <map property="startDate" field="adate">
  ...


Our JSP authors has expressed interest in having the form definition influence
page generation.  I haven't delved into this aspect, but I'm expecting the
requirements to extend to Javascript validation as well.


Hope this helps!

Nino

* Extending PropertyUtils.set/getSimpleProperty to handle maps is actually a
very simple change...



Martin Cooper wrote:

> I'm signed up for the Struts 1.1 task entitled "XML --> ActionForm Code
> Generator", and am working on such a tool at the moment. There has been a
> fair amount of discussion on various types of validation recently, so I
> wanted to throw this variant into the mix and see what people think.
>
> Server-side validation in a Struts application typically happens in two
> different phases. What might be referred to as "early" validation (usually
> just syntactic validation) is done within the form bean (in
> ActionForm.validate()), while "late" (more complex) validation is left to
> the Action to handle.
>
> The question, then, is how best to handle "early" validation in the case
> where the form bean is being generated automatically rather than being
> hand-coded. At this point, I see three alternatives, and this is where I'd
> like to hear what people think.
>
> 1) Do nothing. If the developer wants to do early validation, s/he can
> implement the validate() method by hand to do whatever is necessary.
>
> 2) Generate the validate() method based on validation rules specified in the
> XML definition of the form bean (e.g. within struts-config). This would
> generate a static (i.e. at bean-creation-time) specification of the
> validation algorithm.
>
> 3) Generate a validate() method whose behaviour is defined by an external
> specification (e.g. in XML). This could be along the lines of the Validator
> implementation proposed by David Winterfeldt.
>
> A combination of (2) and (3) might also make sense, where a basic validation
> scheme might take care of existence rules (e.g. 'required') and type
> definitions (e.g. 'must be an integer'), but where more sophisticated
> validation (e.g. must match 'mm/dd/yy') would be left to an external
> validator.
>
> What do people think about this?
>
> --
> Martin Cooper
> Tumbleweed Communications

Reply via email to