Java Reference
In-Depth Information
var xhr = $.post(form.action, params, function (data) {
if (xhr.getResponseHeader('X-Stripes-Success')) {
$('#contact_form').hide();
$('#contact_table').html(data);
}
else {
$('#contact_form').html(data);
}
});
return false ;
}
As you can see, upon finding the success response header, the form
is hidden, and the contact table is refreshed. If the success indicator
is not present, validation errors have occurred, and the contact form
is redisplayed with error messages. Beautiful! The contact form is fully
Ajaxified!
Hey, wait a minute, what about that Cancel button? Well, that's almost
too easy. It just hides the form:
Download email_36/web/WEB-INF/jsp/parts/contact_form.jsp
<s:button name="cancel" onclick="$('#contact_form').hide();"/>
Now the contact form is fully Ajaxified.
15.4
Adding Client-Side Validation
With JavaScript, you can perform client-side form validation so that the
user gets feedback before posting the form to the server. Although this
does not replace server-side validation, it can improve the user's expe-
rience by giving more immediate validation information. It also saves
bandwidth by not sending anything to the server until the form passes
the validation being performed on the client.
The Stripes-Stuff project ( http://www.stripesstuff.org ) includes a plug-in by
Aaron Porter that works with Stripes and jQuery to easily add client-
side validation to a Stripes form. The plug-in discovers and applies the
form's validation criteria as the user is filling out the form. This saves
you a ton of work because you don't have to take all the validation rules
that you've defined in the action bean and duplicate them in JavaScript
code. The plug-in uses the validation metadata to dynamically do the
work for you.
Back on page 209 , we saw how ValidationMetadata provides runtime
validation information. The
<s:field-metadata>
tag complements this
 
 
 
Search WWH ::




Custom Search