struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ted Husted" <ted.hus...@gmail.com>
Subject Re: the ValidateExtends extension
Date Tue, 28 Mar 2006 11:37:09 GMT
On 3/24/06, Vinny <xaymaca@gmail.com> wrote:
> I've been using the ValidateExtends extension to validate nested dynaform to
> great effect. Currently , it provides no method of using the client
> side (javascript) stuff.
> Any plans for that to be included?
> http://www.niallp.pwp.blueyonder.co.uk/strutsvalidatorextends.html

The trick is to patch the extension so that it does what you need to
do, and then contribute the patch back to the project. That's where
many of our niftiest features came from, including the Validator
itself.


> Will this become a non-issue in the new Action framework?

I'm working on a Cookbook for Action 2, and I just put these use cases
on the list of things to include.

The Action 2 validation framework is similar to the Commons Validator,
but uses a "code behind" approach with the configuration files. Each
Action can have it's own "Action-validation.xml" file. When validation
is needed, the validation for every class in the inheritance path is
applied. Here's an example from the Action2-Mailreader (which is
nearly complete).

This is "SubscripionSave-validation.xml" . It's kept alongside the Java class.

<validators>

    <field name="host">
        <field-validator type="requiredstring">
            <message key="error.host.required"/>
        </field-validator>
    </field>

    <field name="subscription.username">
        <field-validator type="requiredstring">
            <message key="error.username.required"/>
        </field-validator>
    </field>

    <field name="subscription.password">
        <field-validator type="requiredstring">
            <message key="error.password.required"/>
        </field-validator>
    </field>

    <field name="subscription.type">
        <field-validator type="requiredstring">
            <message key="error.type.invalid"/>
        </field-validator>
    </field>

</validators>

This is the Subscription-validation.xml. SubscriptionSave is a
subclass of Subscription.

<validators>

    <field name="host">
        <field-validator type="requiredstring">
            <message key="error.host.required"/>
        </field-validator>
    </field>

</validators>

The Subscription action is used to edit or delete records, so the only
validation we need is the "host" property, which is used as a key. The
SubscriptionSave action is used to Insert or Update records. When
SubscriptionSave is validated, the "host" is validated too, because
SubscriptionSave is a subsclass of Subscription.

The Message Resource properties work the same way, but you can also
have a global resource that applies to all classes.

For more about WebWork-style validation see

* http://wiki.opensymphony.com/display/WW/Validation

There's probably some ideas here that we can back-port to Action 1.

-- HTH, Ted.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message