onsubmit
attribute to your h:form
tag that calls the JavaScript validation function generated by s:validatorScript
. s:commonsValidator
and, optionally, s:validatorVar
. s:validatorScript
tag at the end of the h:form
tag's body.Apache Commons Validator对JSF页面验证提供了良好的支持和补充,以下为使用小结:
使用范例
Shale provides three JSP tags that let you use the Commons Validator: s:commonsValidator
, s:validatorVar
, and s:validatorScript
. The first two lets you attach a commons validator to a JSF input component and the third generates JavaScript validation code for validating each JSF component that has one or more Commons validators in a particular form. You can attach as many Commons validators to a single JSF input component as you wish.
commonsValidator Attributes
Name | Description | Type |
---|---|---|
arg | A value that's plugged into the message | String |
client | If true, validation is performed on the client | String |
datePatternStrict | A date pattern using syntax defined in java.text.SimpleDateFormat | String |
mask | A regular expression to which the value must conform | String |
max | The maximum valid value | String |
maxlength | The maximum valid length of the field | String |
message | A message displayed when validation fails | String |
min | The minimum valid value | String |
minlength | The minimum valid length of the field | String |
server | If true, validation is performed on the server | String |
type | The type of validator associated with this tag | String |
type支持类型
Minlength maxlength creditCard required integer intRange
long float floatRange double doubleRange Date email
mask Byte short url
includeJavaScriptUtilities
文摘来源:
1:http://shale.apache.org/shale-core/tagreference.html#commonsValidator
2:http://shale.apache.org/1.0.4/shale-validator/index.html