History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: WW-600
Type: Bug Bug
Status: Closed Closed
Resolution: Won't Fix
Priority: Major Major
Assignee: Philip Luppens
Reporter: Matt Raible
Votes: 1
Watchers: 3
Operations

If you were logged in you would be able to see more operations.
WebWork

Client-side validation doesn't work as advertised

Created: 21/Jul/04 01:37 PM   Updated: 10/Feb/07 09:00 AM
Component/s: Views
Affects Version/s: 2.1
Fix Version/s: 2.1.1, 2.1.8, 2.2.5

Environment: JDK 1.4.2, Tomcat 5.0.27, WebWork CVS (20040721)


 Description  « Hide
The client-side JavaScript doesn't work as advertised on:

http://wiki.opensymphony.com/display/WW/Client-Side+Validation

I have the following form:

<ww:form action="'saveUser'" validate="true" cssClass="'detail'" method="'post'">

This generates the following onsubmit handler:

onsubmit="return(${parameters.name}_validate())"

And the following JavaScript after the form:

<script type="text/javascript">
    function ${parameters.name}_validate() {
        var form = document.forms['${parameters.name}'];
        var focus = ${parameters.name}_validate_actual();
        if (focus != null) {
            form.elements[focus].focus();
            if (form.elements[focus].type == 'text' || form.elements[focus].type == 'textarea') {
                form.elements[focus].select();
            }
            return false;
        } else {
            return true;
        }
    }

function ${parameters.name}_validate_actual() {
        var form = document.forms['${parameters.name}'];
        // cannot find any applicable validators
        return null;
    }
    </script>

If I add name="'user'" to the <ww:form>, then the JavaScript looks right, but I get:

function user_validate_actual() {
        var form = document.forms['user'];
        // cannot find any applicable validators
        return null;
    }

I have the following in validators.xml:

<validator name="requiredstring"
        class="com.opensymphony.webwork.validators.JavaScriptRequiredStringValidator"/>

Oddly enough, XMLBuddy (in Eclipse) says that "name" must be declared.



 All   Comments   Change History      Sort Order:
Patrick Lightbody - [21/Jul/04 03:56 PM ]
Mark Woon has fixed most of this for the 2.1.1 release.

Patrick Lightbody - [21/Jul/04 04:13 PM ]
Mark is our new validation/javascript guru

Mark Woon - [23/Jul/04 08:06 PM ]
The first part is a problem with the documentation. The name attribute is required for client-side validation to work.

As for the second problem, I need a bit more information. Matt, what validation rule(s) are you using? validators.xml only tells WW what validators are available. It doesn't actually set it up for use. You also need an ActionClass-validation.xml file with the validation rules (were ActionClass is the name of your Action class).

The simplest way to test this is to see if validation works at all when you submit the form.

Patrick Lightbody - [26/Aug/04 06:28 PM ]
Matt,
I haven't been able to reproduce this, even with the sample code you sent me. I'm going to go ahead and release WW 2.1.1 and then maybe afterwards we can look in to this some more.

yufeng - [25/Jan/05 07:39 AM ]
i have the same question
Environment: JDK 1.4.1, weblogic 8.1.2
webwork-2.1.6,
the action name is RegisterAction
the name of validation file is
"RegisterAction-validation.xml"
content is:
<validators>
    <field name="usrname">
        <field-validator type="requiredstring">
            <message>cant null</message>
        </field-validator>
    </field>
    <field name="password">
        <field-validator type="requiredstring">
            <message>must enter password</message>
        </field-validator>
    </field>
     <field name="salary">
        <field-validator type="requiredstring">
            <message>must enter salary</message>
        </field-validator>
    </field>
</validators>



Matt Raible - [24/Feb/06 01:31 AM ]
This still seems to be an issue with visitor validation in 2.2.1. Here's the JavaScript that's rendered in the final output when I have validate="true" on my form.

<script>
function customOnsubmit() {





}
</script>

<script>
    function validateForm_signup() {
        form = document.getElementById("signup");
        clearErrorMessages(form);
        clearErrorLabels(form);

var errors = false;

return !errors;
    }
</script>

Here's my SignupAction-validation.xml:

<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.dtd">
<validators>
    <field name="user">
        <field-validator type="visitor">
            <param name="appendPrefix">false</param>
            <message/>
        </field-validator>
    </field>
</validators>

And here's my User-validation.xml (which works fine for server-side validation):

<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
    "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
<validators>
    <field name="user.username">
        <field-validator type="requiredstring">
            <message key="errors.required"/>
        </field-validator>
    </field>
    <field name="user.password">
        <field-validator type="requiredstring">
            <message key="errors.required"/>
        </field-validator>
    </field>
    <field name="user.confirmPassword">
        <field-validator type="requiredstring">
            <message key="errors.required"/>
        </field-validator>
        <field-validator type="fieldexpression">
            <param name="expression">
                (user.confirmPassword.equals(user.password))
            </param>
            <message key="errors.twofields"/>
        </field-validator>
    </field>
    <field name="user.firstName">
        <field-validator type="requiredstring">
            <message key="errors.required"/>
        </field-validator>
    </field>
    <field name="user.lastName">
        <field-validator type="requiredstring">
            <message key="errors.required"/>
        </field-validator>
    </field>
    <field name="user.address.city">
        <field-validator type="requiredstring">
            <message key="errors.required"/>
        </field-validator>
    </field>
    <field name="user.address.province">
        <field-validator type="requiredstring">
            <message key="errors.required"/>
        </field-validator>
    </field>
    <field name="user.address.country">
        <field-validator type="requiredstring">
            <message key="errors.required"/>
        </field-validator>
    </field>
    <field name="user.address.postalCode">
        <field-validator type="requiredstring">
            <message key="errors.required"/>
        </field-validator>
        <!-- Can't get regex validation to work -->
        <!--field-validator type="fieldexpression">
            <param name="expression">
                user.postalCode.matches('^\d{5}\d*$'))
            </param>
            <message key="errors.zip"/>
        </field-validator-->
    </field>
    <field name="user.email">
        <field-validator type="requiredstring">
            <message key="errors.required"/>
        </field-validator>
        <field-validator type="email">
            <message key="errors.email"/>
        </field-validator>
    </field>
    <!-- Can't get regex validation to work -->
    <!--field name="user.phoneNumber">
        <field-validator type="fieldexpression">
            <param name="expression">
                (user.phoneNumber.matches('^\(?(\d{3})\)?[-| ]?(\d{3})[-| ]?(\d{4})$'))
            </param>
            <message key="errors.phone"/>
        </field-validator>
    </field-->
    <field name="user.website">
        <field-validator type="requiredstring">
            <message key="errors.required"/>
        </field-validator>
    </field>
    <field name="user.passwordHint">
        <field-validator type="requiredstring">
            <message key="errors.required"/>
        </field-validator>
    </field>
</validators>



Claus Ibsen - [24/Feb/06 03:22 AM ]
I tired the showcase from CVS HEAD and the pure clientside validation worked there. But I don't think it uses the Visitor validation.

I think that in 2.2.1 the showcase pure clientside validation did not work.

At least my own little app didn't work with 2.21 but with CVS HEAD.

Patrick Lightbody - [05/Mar/06 02:26 PM ]
Matt,
We're on a time crunch to fix 2.2.2 before we go in to the Struts incubator. Basically, the gist of this issue is that pure client side validation (as opposed to ajax style) only supports very basic validation rules. That means that visitor rules won't work until we spend more time on it :(

I have to push this back to 2.3 (aka Struts Action 2.0), but if you want to try to hack at form-close-validate.ftl, you might be able to get support in there.

Philip Luppens - [10/Feb/07 09:00 AM ]
Client side validation is indeed not working too well; some messages get created at runtime (eg. when using int validators, and using non-valid integer, the non-integer value message gets stored).

Marking this as won't fix, we'll try to have a better look at this at Struts 2.