Java Reference
In-Depth Information
Figure 15.14: Initial contact form with client-side validation
Finally, the default behavior of the plug-in is to add the invalid CSS
class to input controls that fail validation. So, we'll highlight them in
the same way as we were doing with the Stripes error class:
Download ajax/web/css/style.css
input.error, input.invalid {
border-color: red;
background-color: #FFCCCC;
}
That's all there is to it. The initial form is shown in Figure 15.14 . Notice
that the Email field is highlighted because it fails validation—it is a
required field. Also, the two submit buttons, Save and Cancel , are
disabled because of the presence of validation errors.
As the user types values into the fields, these are highlighted (or not),
and the submit buttons are enabled or disabled, according to the pres-
ence or absence of validation errors. When executing JavaScript code
with each keystroke, it's best to turn off the browser's autocomplete fea-
ture with the autocomplete= attribute on the text fields. But wait—that
attribute is not recognized by the <s:text> tag because it's not techni-
cally valid HTML. Are we out of luck? Of course not. Stripes includes
another version of its tag library that accepts dynamic attributes:
Download ajax/web/WEB-INF/jsp/common/taglibs.jsp
<%@taglib prefix="s-dyn"
uri="http://stripes.sourceforge.net/stripes-dynattr.tld"%>
We can keep using the original version and use this dynamic version
whenever we need unrecognized attributes:
Download ajax/web/WEB-INF/jsp/client_side_validation.jsp
<s-dyn:text id="contact.email" name="contact.email"
autocomplete="off"/>
 
 
Search WWH ::




Custom Search