@validator"
From Documentation
m ((via JWB)) |
m ((via JWB)) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
=Syntax= | =Syntax= | ||
− | < | + | <code>@validator(</code> ''[EL-expression], [arbitraryKey]=[EL-expression] '' <code>)</code> |
= Description = | = Description = | ||
'''Target Attribute:''' any (except viewModel, validationMessages, form, and event attributes) | '''Target Attribute:''' any (except viewModel, validationMessages, form, and event attributes) | ||
− | '''Purpose:''' It should be used with < | + | '''Purpose:''' It should be used with <code>@bind</code>, <code>@load</code>, <code>@save</code>. It applies a validator to validate data when saving to ViewModel. |
The evaluation result of EL expression should be a <javadoc> org.zkoss.bind.Validator </javadoc> object. You can append arbitrary arguments in key-value pair with comma separated to pass it to the Validator object. Built-in Validator is referenced by a string literal as its name. | The evaluation result of EL expression should be a <javadoc> org.zkoss.bind.Validator </javadoc> object. You can append arbitrary arguments in key-value pair with comma separated to pass it to the Validator object. Built-in Validator is referenced by a string literal as its name. | ||
Line 39: | Line 39: | ||
=Version History= | =Version History= | ||
− | + | ||
{| class='wikitable' | width="100%" | {| class='wikitable' | width="100%" | ||
! Version !! Date !! Content | ! Version !! Date !! Content |
Latest revision as of 07:35, 8 July 2022
This article is out of date, please refer to zk-mvvm-book/8.0/syntax/data_binding/validator for more up to date information.
Syntax
@validator(
[EL-expression], [arbitraryKey]=[EL-expression] )
Description
Target Attribute: any (except viewModel, validationMessages, form, and event attributes)
Purpose: It should be used with @bind
, @load
, @save
. It applies a validator to validate data when saving to ViewModel.
The evaluation result of EL expression should be a Validator object. You can append arbitrary arguments in key-value pair with comma separated to pass it to the Validator object. Built-in Validator is referenced by a string literal as its name.
- [arbitraryKey]=[EL-expression]
- It's key-value pairs basically. You can write multiple key-value pairs with different key names.
- An EL expression without key is set to a default key named "value" implicitly.
- Due to each annotation has different functions, some annotations may ignore key-value pair expression other than default key, e.g.@id.
- [arbitraryKey]
- It could be any name, it's used as a key for parameter related Java annotation in a ViewModel.
Example
Use built-in validator named beanValidator
<window id="win" apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init(foo.MyViewModel)">
<textbox value="@bind(vm.user.lastName) @validator('beanValidator')" />
</window>
Use custom validator
<datebox id="cdbox" value="@bind(fx.creationDate) @validator(vm.creationDateValidator)"/>
Version History
Version | Date | Content |
---|---|---|
6.0.0 | February 2012 | The MVVM was introduced. |