Java Reference
In-Depth Information
by translating the validation metadata into JavaScript key-value pairs,
as follows:
{
'contact.email':
{required: true ,trim: true ,typeConverter:'EmailTypeConverter'},
'contact.firstName':
{trim: true ,maxlength:25,typeConverter:'StringTypeConverter'},
'contact.lastName':
{trim: true ,minlength:2,maxlength:40,typeConverter:'StringTypeConverter'},
'contact.phoneNumber':
{typeConverter:'PhoneNumberTypeConverterFormatter'},
'contact.birthDate':
{type:'Date',trim: true ,typeConverter:'DateTypeConverter'}
'contact.gender':
{typeConverter:'EnumeratedTypeConverter'},
}
The plug-in uses this information to validate the fields on the fly. Let's
use it with the contact form as an example.
To set up the plug-in, import the JavaScript libraries, in order:
Download ajax/web/WEB-INF/jsp/client_side_validation.jsp
<script src="${contextPath}/js/jquery.js"
type="text/javascript"> </script>
<script src="${contextPath}/js/jquery.validation.js"
type="text/javascript"> </script>
<script src="${contextPath}/js/stripes.jquery.validation.js"
type="text/javascript"> </script>
Next, right before the closing form tag, add the <s:field-metadata>
tag
followed by a call to applyStripesValidation ( ), like this:
Download ajax/web/WEB-INF/jsp/client_side_validation.jsp
<s:form beanclass="stripesbook.action.ClientFormActionBean">
<!-- form input controls... -->
<s:field-metadata var="fmd"/>
<script type="text/javascript">
applyStripesValidation('${fmd.formId}', ${fmd});
</script>
</s:form>
The <s:field-metadata> tag places the validation metadata in the vari-
able, fmd . You can then access the information with ${fmd} , as well as
the generated form ID with ${fmd.formId} . These two pieces of informa-
tion must be passed to applyStripesValidation ( ).
 
Search WWH ::




Custom Search