To give the user some feedback why her/his submitted data was rejected
there is a special taglib "xsp-formval". Declare its name space as
usual.
If only interested in validation results, just:
 |  |  |
 |
<xsp-formval:on-ok name="persons">
<myapp:error>(ERROR)</myapp:error>
</xsp-formval:on-ok>
|  |
 |  |  |
Alternatively, if you just want a boolean value from the logicsheet
if a test is successful, use this method:
 |  |  |
 |
<xsp:logic>
if (!<xsp-formval:is-ok name="persons"/>) {
<myapp:error>(ERROR)</myapp:error>
};
</xsp:logic>
|  |
 |  |  |
Internationalization issues are a separate concern and are not
discussed here.
Currently the following validation result codes are supported:
tag
| Meaning
|
xsp-formval:is-ok
| no error occurred,
parameter successfully
checked
|
xsp-formval:is-error
| some error occurred,
this is a result that
is never set but serves
as a comparison target
|
xsp-formval:is-null
| the parameter is null but
isn't allowed to
|
xsp-formval:is-toosmall
| either value or
length in case of a
string is less than
the specified
minimum
|
xsp-formval:is-toolarge
| either value or
length in case of a
string is greater
than the specified
maximum
|
xsp-formval:is-nomatch
| a string parameter's
value is not matched
by the specified
regular expression
|
xsp-formval:is-notpresent
| this is returned
when the result of
a validation is
requested but no
such result is
found in the
request attribute
|
For debugging purposes or if you would like to iterate over the
validation results, xsp-formval:results
returns a
java.util.Map
containing them all.
If you would like to be more specific what went wrong, you can
query the descriptor file for attributes.
First set the url of the file or resource that contains the
parameter descriptions and constraint sets. This needs to be an
ancestor to all other tags (of this taglib). Multiple use of this
tag is allowed (although probably not necessary).
You need to do this only if you plan to query the
descriptor file or if you'd like to use the shorthand
below.
 |  |  |
 |
<xsp-formval:descriptor name="descriptor.xml" constraint-set="reservation">
deposit must be at least EUR
<xsp-formval:get-attribute parameter="deposit" name="min"/>
</xsp-formval:descriptor>
|  |
 |  |  |
If you need to use one parameter a lot, there's a short hand. Use
this e.g. if you'd like to set up the properties of an input tag
according to the information from the descriptor file or if you'd
like to give detailed error messages.
Note that you can specify additional attributes in the
description file that are not understood (and therefore ignored)
by the FormValidatorAction but that could be queried here. This
might be e.g. the size of the input field which might be
different from the max-len a parameter can take.
 |  |  |
 |
<xsp-formval:descriptor name="descriptor.xml" constraint-set="car-reservation">
<xsp-formval:validate name="deposit">
<xsp:logic>
if (<xsp-formval:is-null/>) {
<myapp:error> (you must specify a deposit)) </myapp:error>
} else if ( <xsp-formval:is-toosmall/> ) {
<myapp:error>
(deposit is too small (< <xsp-formval:get-attribute name="min"/>))
</myapp:error>
} else if ( <xsp-formval:is-toolarge/> ) {
<myapp:error>
(deposit is too large (> <xsp-formval:get-attribute name="max"/>))
</myapp:error>
} else {
<myapp:error> (ERROR) </myapp:error>
};
</xsp:logic>
</xsp-formval:validate>
</xsp-formval:descriptor>
|  |
 |  |  |