Last updated April 10, 2011 16:35, by sdouglass
Feedicon  

Tag Body JSON Object

Additional validation configuration can be provided in a JSON object in the body of the validate tag. For example:

  <jsr303js:validate commandName="testModelBean">{ 'fieldName' : { propertyName : 'propertyValue' } }</jsr303js:validate>

Create an object with a structure like this:

  { 
   'fieldNameOne' : { 
     'propertyOne' : 'valueOne', 
     'propertyTwo' : 'valueTwo'
   },
   'fieldNameTwo' : {
     'propertyOne' : 'valueThree',
     'propertyThree' : 'valueFour'
   }
 }

JavaScript Date Parsing

Some simple JavaScript date parsing code is included to support the @Future and @Past validation annotations. Dates are parsed according to simple date formats similar to Java date formats.

d day of month
m minute of hour
M month of year
a AM/PM, required for 12-hour time
y year, required
h 12-hour hour, requires 'a'
H 24-hour hour, cannot be used with 'a'
s second of minute

Only use up to one of each character per format. Year is required at a minimum. Other fields not specified in the format will receive default values. 1-3 digit years will be translated into years according to the code in the JavaScript Date constructor that takes year, month, day, hour, minute, and second. Here are some example date formats:

M/d/y Month, day, year, the default
d/M/y h:ma Day, month, year, 12-hour hour, minute, AM/PM
H:m:s 24-hour hour, minute, second

An example of providing date formats for two fields, "future" and "past":

  <jsr303js:validate commandName="testModelBean">{ future : { dateFormat : 'M/d/y' }, past : { dateFormat : 'M/d/y' } }</jsr303js:validate>

JavaScript E-mail Validation

The Hibernate Validator e-mail validation does not require e-mail addresses to have a top level domain, aka "TLD" (e.g. '.com', '.org', etc.), per the RFC for e-mail addresse. However, in most cases users will likely want to require a TLD. The JavaScript e-mail validation defaults to requiring a TLD, however you can switch to making the TLD optional on a per field basis by providing configuration like the following in the tag body JSON object:

 {
    'emailAddress' : { 'tldOptional' : true } 
 }

Please see this JIRA issue for Hibernate Validator:

http://opensource.atlassian.com/projects/hibernate/browse/HV-41

Once they have provided an attribute allowing users to decide if the TLD should be optional or required JSR303JS will be updated to just use that attribute, instead of checking for the configuration in the tag body JSON object.

  • Mysql
  • Glassfish
  • Jruby
  • Rails
  • Nblogo
Terms of Use; Privacy Policy;
© 2014, Oracle Corporation and/or its affiliates
(revision 20160708.bf2ac18)
 
 
Close
loading
Please Confirm
Close