Reference Binding"
From Documentation
Line 49: | Line 49: | ||
</source> | </source> | ||
− | ''' | + | |
+ | '''Modularize view example - person.zul''' | ||
+ | |||
<source lang="xml" high="3,6"> | <source lang="xml" high="3,6"> | ||
<vlayout> | <vlayout> | ||
Line 61: | Line 63: | ||
</source> | </source> | ||
− | In above | + | In the example above, we have a veiw - person.zul which binds components to '''p.firstName''' and '''p.lastName'''. This view could be reused by other views that provides a reference '''p'''. |
=Version History= | =Version History= |
Revision as of 03:18, 12 March 2012
Since 6.0.1
Make an expression reference
Reference binding allows us to reference an EL expression with a customized name. We can use this reference in another EL expression nested in the component that is binded to this reference. Typically, we use reference binding to shorten expressions or to modularize the view[1].
Steps to implement 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
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>
As shown in the example above, we add a reference @ref to vm.person with a name p to vlayout. This way, p inside the vlayout can be used by other EL expressions.
Modularize 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>
Modularize 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 the example above, we have a veiw - person.zul which binds components to p.firstName and p.lastName. This view could be reused by other views that provides a reference p.
Version History
Version | Date | Content |
---|---|---|
6.0.1 | May 2012 | The new reference-binding feature. |