PDA

View Full Version : Client Side Validation (Commons Validator)


Film Noir
Jun 9th, 2008, 04:40 PM
Greetings,

I'm fairly new to Spring and struggling to get client-side validation working correctly.

I've managed to get server-side validation working correctly, but the same configuration will not work for client-side.

I've been following chapter 17 of the springmodules docs (it won't let me post a link):


I've added the validation tag library, and added the javascript tag and modified the onSubmit function of the form:



<validator:javascript formName="vendor" staticJavascript="false" xhtml="true" cdata="false"/>

....

<form:form name="vendor" method="post" action="vendor/updateProfile.htm" commandName="userVendor" enctype="multipart/form-data" onsubmit="return validateVendor(this)">



When I view the page source this is the generated javascript:


<script type="text/javascript">

var bCancel = false;

function validateVendor(form) {
if (bCancel)
return true;
else
return validateEmail(form);
}

function email() {
this.aa = new Array("contactEmail", "errors.email", new Function ("varName", " return this[varName];"));
}


</script>


The problem is when I submit the form - it throws a 'validateEmail() is not defined' error. It can't locate the validateEmail() function defined in the validator-rules.xml ?

Has anyone any ideas why this may be happening? It there an extra javascript file I need to import into the page?

I've defined the following validation.xml:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE form-validation PUBLIC
"-//Apache Software Foundation//DTD
Commons Validator Rules Configuration 1.1//EN"
"...../validator_1_3_0.dtd">

<form-validation>
<formset>
<field property="contactEmail" depends="required,email">
<arg key="error.vendorEmail" />
</field>
</form>
</formset>
</form-validation>


Thanks,
Alan.

Film Noir
Jun 10th, 2008, 04:04 AM
On further reading should the <validator:javascript /> tag be placed within the form tag, or after it?

I've tried both those places, and the inside the <head> tag, without success.

brajput24
Jun 19th, 2008, 03:14 AM
I'm fairly new to Spring and struggling to get Server side validation.

Can you send me some sample code for it .

Regards,
Brijesh Singh

Greetings,

I'm fairly new to Spring and struggling to get client-side validation working correctly.

I've managed to get server-side validation working correctly, but the same configuration will not work for client-side.

I've been following chapter 17 of the springmodules docs (it won't let me post a link):


I've added the validation tag library, and added the javascript tag and modified the onSubmit function of the form:



<validator:javascript formName="vendor" staticJavascript="false" xhtml="true" cdata="false"/>

....

<form:form name="vendor" method="post" action="vendor/updateProfile.htm" commandName="userVendor" enctype="multipart/form-data" onsubmit="return validateVendor(this)">



When I view the page source this is the generated javascript:


<script type="text/javascript">

var bCancel = false;

function validateVendor(form) {
if (bCancel)
return true;
else
return validateEmail(form);
}

function email() {
this.aa = new Array("contactEmail", "errors.email", new Function ("varName", " return this[varName];"));
}


</script>


The problem is when I submit the form - it throws a 'validateEmail() is not defined' error. It can't locate the validateEmail() function defined in the validator-rules.xml ?

Has anyone any ideas why this may be happening? It there an extra javascript file I need to import into the page?

I've defined the following validation.xml:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE form-validation PUBLIC
"-//Apache Software Foundation//DTD
Commons Validator Rules Configuration 1.1//EN"
"...../validator_1_3_0.dtd">

<form-validation>
<formset>
<field property="contactEmail" depends="required,email">
<arg key="error.vendorEmail" />
</field>
</form>
</formset>
</form-validation>


Thanks,
Alan.

buntyindia
Aug 1st, 2008, 02:27 PM
I also need example/sample code on commons validator client side validation (JavaScript) in spring.

Can we pop up a edit message ?