Reference Binding"
From Documentation
Dennischen (talk | contribs) |
Dennischen (talk | contribs) |
||
Line 2: | Line 2: | ||
{{Template:UnderConstruction}} | {{Template:UnderConstruction}} | ||
+ | |||
+ | __TOC__ | ||
Since 6.0.1 | Since 6.0.1 | ||
− | Reference binding allows us to make a reference for a EL expression with a custom name. The reference could be referred in another EL expression (Have to nested in the component has this reference binding). Typically we use reference binding to make expression shorter or modularize the view. | + | =Make an expression reference= |
+ | |||
+ | Reference binding allows us to make a reference for a EL expression with a custom name. The reference could be referred in another EL expression (Have to nested in the component has this reference binding). Typically we use reference binding to make expression shorter or modularize the view<ref>When using this feature, you have to avoid to save to a first-term only expression, read [[ZK_Developer%27s_Reference/MVVM/Data_Binding/EL_Expression#Limitation]] for more detail.</ref>. | ||
Steps to use this feature: | Steps to use this feature: | ||
# Bind a custom attribute on a component with <tt> @ref </tt>. | # Bind a custom attribute on a component with <tt> @ref </tt>. | ||
− | # Use the custom attribute in | + | # Use the custom attribute in other EL expression that nested in children component |
+ | |||
+ | <blockquote> | ||
+ | ---- | ||
+ | <references/> | ||
+ | </blockquote> | ||
'''Basic usage example''' | '''Basic usage example''' | ||
Line 27: | Line 36: | ||
</source> | </source> | ||
+ | In above example, we add a reference to '''vm.person''' with name '''p''' to the vlayout. So, inside the vlayout, the '''p''' could be used by other EL expression. | ||
+ | |||
'''Moudlarize view example''' | '''Moudlarize view example''' | ||
Line 49: | Line 60: | ||
</vlayout> | </vlayout> | ||
</source> | </source> | ||
+ | |||
+ | In above example, we have a veiw - person.zul which binds components to '''p.firstName''' and '''p.lastName'''. This view could be reused by other view that provides a reference '''p'''. | ||
+ | |||
+ | |||
=Version History= | =Version History= |
Revision as of 03:59, 3 March 2012
Since 6.0.1
Make an expression reference
Reference binding allows us to make a reference for a EL expression with a custom name. The reference could be referred in another EL expression (Have to nested in the component has this reference binding). Typically we use reference binding to make expression shorter or modularize the view[1].
Steps to use this feature:
- Bind a custom attribute on a component with @ref .
- Use the custom attribute in other EL expression that nested in children component
- ↑ When using this feature, you have to avoid to save to a first-term only expression, read ZK_Developer's_Reference/MVVM/Data_Binding/EL_Expression#Limitation for more detail.
Basic usage example
<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>
In above example, we add a reference to vm.person with name p to the vlayout. So, inside the vlayout, the p could be used by other EL expression.
Moudlarize view example
<window apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('foo.MyVM')">
<include p="@ref(vm.person1)" src="person.zul"/>
<include p="@ref(vm.person2)" src="person.zul"/>
</window>
Moudlarize view example - person.zul
<vlayout>
<hlayout>
First Name: <textbox value="@bind(p.firstName)"/>
</hlayout>
<hlayout>
Last Name: <textbox value="@bind(p.lastName)"/>
</hlayout>
</vlayout>
In above example, we have a veiw - person.zul which binds components to p.firstName and p.lastName. This view could be reused by other view that provides a reference p.
Version History
Version | Date | Content |
---|---|---|
6.0.1 | May 2012 | The new reference-binding feature. |