New Features of ZK 6.0.1"
Tmillsclare (talk | contribs) |
Tmillsclare (talk | contribs) |
||
Line 116: | Line 116: | ||
<textbox value="@bind(vm.value) @validator('bar')"/> | <textbox value="@bind(vm.value) @validator('bar')"/> | ||
</source> | </source> | ||
+ | |||
+ | For more information please consult the [[ZK_Developer's_Reference/MVVM/Data_Binding/Validator#Register_Application_Level_Validators | developer's reference]]. | ||
=Download & other resources= | =Download & other resources= |
Revision as of 08:55, 27 April 2012
Timothy Clare, Potix Corporation
April 2, 2012
ZK 6.0.1
Reference Binding
- Available for ZK:
Reference binding allows us to reference an expression with a customized name. We can use this reference in another EL expression nested in the component that is binded to this reference.
A simple example is as follows:
<window apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('foo.MyVM')">
<vlayout p="@ref(vm.person)">
<hlayout>
First Name: <textbox value="@bind(p.firstName)" />
</hlayout>
<hlayout>
Last Name: <textbox value="@bind(p.lastName)" />
</hlayout>
</vlayout>
</window>
Steps to use this feature:
- Bind a custom attribute on a component with @ref .
- Use the custom attribute in other EL expressions that are nested in children components
The above code shows these implemented steps, for more information and more uses please visit the developer's reference.
Children binding now supports a converter
It is now possible to specify a converter when loading children. There is a default converter which attempts to coerce the argument object into a List. The following code provides a sample for this:
<hlayout children="@init(vm.items) @converter(vm.itemConverter)">
<template name="children">
<label value="@load(each) "/>
</template>
</hlayout>
For more information please see the developer's reference.
Form Bean Validator
- Available for ZK:
Since 6.0.1
This feature is similar to the Bean Validator, as it integrates JavaBean Validation and validates a bean's all saving properties. For the configuration and JavaBean usage, please refer to Prepare_to_Use_JSR_303
Usage
Use this validator with the name formBeanValidator and set a unique prefix key by prefix argument of validator. When any property of the bean is invalid, it puts the invalid message to validation message holder with key prefix+propertyName.
<window id="win" apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init(foo.MyViewModel)"
validationMessages="@id('vmsgs')">
<grid width="600px" form="@id('fx') @load(vm.user) @save(vm.user,after='save')
@validator('formBeanValidator',prefix='p_')">
<textbox value="@bind(fx.firstName)"/>
<label value="@load(vmsgs['p_firstName'])"/>
</grid>
<!--more components-->
</window>
For more information please refer to the developer's reference.
Application Level Converters
- Available for ZK:
It is now possible to register a converter for the entire application which is shared between all binders. This is done by first setting the library-property(org.zkoss.bind.appConverters) in zk.xml.
<library-property>
<name>org.zkoss.bind.appConverters</name>
<value>foo=my.FooConverter,bar=my.BarConverter</value>
</library-property>
Then it is possible to use them by the converter name.
<label value="@load(vm.message) @converter('foo')"/>
<label value="@load(vm.message) @converter('bar')"/>
For more information please consult the developer's reference.
Register Application Level Validators
- Available for ZK:
It is now possible to register a validators for the application by setting library-property(org.zkoss.bind.appValidators) in zk.xml.
<library-property>
<name>org.zkoss.bind.appValidators</name>
<value>foo=my.FooValidator,bar=my.BarValidator</value>
</library-property>
Then it is possible to use them by the validator name.
<textbox value="@bind(vm.name) @validator('foo')"/>
<textbox value="@bind(vm.value) @validator('bar')"/>
For more information please consult the developer's reference.
Download & other resources
Comments
Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License. |