I'm copying a posting I made to the user list (before I knew about the
dev-list) as I think it has many similarities to the current discussions:

The code I wrote has gone on hold due to outside circumstances and whilst I
look at the Struts Validator. I'll also be thinking of a way of generating
the html completely dynamically using XML (equivalent to the data-mapping
tag below) and XSLT as the forms (potentially thousands) in the application
have an identical look and feel.


Regards,


Sean


---------------------------------------------------------------------------------------------------------------------------------------------------
All,

If anyone read my last (and first) posting to the list they'll know that
I'm new to Struts. Anyway, after deciding to plan on using Struts in my
next project, I felt that for the application many Beans would be required
for the many, many, many, forms. All of which will need extensive
validation. So I decided that ideally one shouldn't need to define a Bean
for each form, only define the data on the form to be picked up by the
ActionServlet, validated and then passed to the custom Action class.
Anyway, I thought that it would be a lot of work to implement and also read
the current plans for version 1.1 (of Struts) and came up with a half-way
house, for us in the interim.

However, at the w/e I got bored and ended up writing my initial design and
it is already just about useable. It's not complete and I'm sure there's
lots of missing pieces and bugs. I intend to carry on with it this week as
much as I can, but thought I'd just pass on more about it. Once it is more
useable I'll willingly pass on the code to others, but it can't be easily
back-engineered into newer releases of Struts. But at the least it may
spark
some ideas for the Struts developers. My implementation of course is very
rough and there are much better ways to do it, and I'm in no doubt that the
team (knowing the framework inside-out) could do it much better. (I also
have other ideas that would be cool too)

Anyway, he's how it is used:
(I've directly re-coded existing classes where necessary, and also made a
new package. All original Struts functionality remains - I hope!.)

1. in the struts-config.xml file you have a definition for your forms, e.g.

  <action-mappings>
    <action path="/order"
            type="com.bar.fu.OrderAction"
         name="orderForm"
         input="/order.jsp" >
      <forward name="success" path="/confirmOrder.jsp" />
    </action>
  </action-mappings>
<data-mappings>
    <data-mapping name="orderForm">
      <property-mapping viewName="customerID" modelName="customerID" type
="int" required="true" />
      <property-mapping viewName="productID" modelName="productID" type
="int" required="true" />
      <property-mapping viewName="price" modelName="price" type="float"
required="true" regExpr="" />
    </data-mapping>
</data-mappings>

An additional property-mapping attribute is 'defaultValue'.

2. If validation is specified in web.xml then each data value is validated
according to the data-type to be converted to and any regular expressions
given (haven't implemented the regExp bit yet). Failure naturally takes the
user back to the 'input' page (in the action-mappings).

3. All that happens then is that the ActionForm given in Action.process()
is a subclass called org.apache.struts.data.DataForm which is a 'glorified
Hashtable' of the values defined in the data-mapping for that form.

4. There will also be populate and extract methods on the DataForm class to
automatically 'move' values to and from the DataForm and a Bean (or EJB)
given.


Using this extension to Struts will greatly speed the development of our
next project, but it would be good if something like it could be
incorporated into the original code-stream.


Anyway, if people are interested in it then let me know and once I've put
some more work into it I'll be happy to pass it on.


Regards,



Sean

--------------------------------------------------
Dr Sean Radford, MBBS, MSc
Senior Consultant
Agora Professional Services Ltd
[EMAIL PROTECTED]
http://www.agora.co.uk

Reply via email to