Form Validation | design
The Validwhen validator provided with struts 1.2 makes it easy to create more complex and flexible forms validation.
For example, we want to verify that the user entered the same password two times, or only if the user fills out the form's "Last Name," the form's "name" is required.
Validwhen needs to declare a VAR field called Test, the value of which is a Boolean expression, such as:
Validation succeeds when a Boolean expression returns True. Below are some elements that allow the expression to be sent:
string decimal, hexadecimal, or octal representations of literal literals in single or double quotes null indicates that an empty string without input can use any field name in the form, such as an customerage indexed field that is explicitly referenced, such as childlastname[2] an indexed field that is implicitly referenced , such as childlastname[], that represents the form that is currently being validated using the same index literal as the field *this*
Cases:
This code below indicates that the field is valid only if the Sendnewsletter field is empty, or if the field EmailAddress is not empty
<field property= "EmailAddress" depends= "Validwhen" > <arg0 key= "Userinfo.emailAddress.label"/> < Var> <var-name>test</var-name> <var-value> (sendnewsletter = = null) or (*this*!= n ull) </var-value> </var> </field> The example below shows that the field quantity is necessary only if the corresponding PartNumber exists
The example below shows that the field quantity is necessary only if the corresponding PartNumber exists
<field property= "Quantity" indexedlistproperty= "OrderLines" depends= "Validwhen" > <arg0 "key=" Orderform.quantity.label "/> <var> <var-name>test</var-name> <var-value> ;((Orderlines[].partnumber = = null) or (*this*!= null)) </var-value> </var> </field> The example below shows , if you enter a height of less than 60 inches, you cannot do Nbapointguard
The example below shows that if you enter a height of less than 60 inches, you cannot do Nbapointguard
<field property= "Nbapointguard" depends= "Validwhen" > <arg0 key= "Careers.nbaPointGuard.label"/> ;var> <var-name>test</var-name> <var-value> (heightininches >=) or (*this* = = NULL)) </var-value> </var> </field>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.