-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hello all,
I'm trying to figure out a way to add bind to component inside a macro component. The idea is to provide data binding capability to the macro component, to simplify I'll put only one component, this is the macro component that needs binding.
comboBind.zul
<combobox id="combo1" model="${arg.comboModel}"> <comboitem self="@{each=item}" label="@{item.name}" value="@{item}"/> </combobox>
On my the zul page the usage should be like this. The 'valueBinded' attribute is a pseudo-attribute just to show the idea, but everything else works fine:
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" arg0="./win" ?> <window id="win"> <comboBind id="comboBind" comboModel="@{someList}" valueBinded="@{bean.attributeA}" /> </window>
I've tried to change the comboBind.zul to this:
<combobox id="combo1" model="${arg.comboModel}" selectedItem="${arg.valueBinded}"> ...
This does half job, because it only reads the value on 'arg.valueBinded'. If I choose a value on combo1 the value isn't setted to 'bean.attributeA'. So, tried another way, instead of $ I change to @:
<combobox id="combo1" model="${arg.comboModel}" selectedItem="@{arg.valueBinded}"> ...
This as the prior attempt works for reading data, but when I change the selected option on 'combo1' and forces binder.loadAll() the combobox get empty value.
I believe this is because the binder tries to set the selected value on the 'arg' object, instead of the actual bean (bean.attributeA). I'm thinking in a way to get the binder from the parent and dynamically add the binding information, but I don't know how to do this.
Anybody has any idea on how to bind the component inside the macro componet?
Regards,
I tried another approach, and now I'm getting an error.
On the comboBind's java class I add this method:
public void configureBinder(DataBinder binder) { binder.bindBean 'bean', page.getVariable('bean') binder.addBinding combo1, 'selectedItem', 'bean.attributeA' binder.loadAll() }
The binder I pass as parameter is the binder from the parent window, created by AnnotatedDataBinderInit. When binder.loadAll() is called I get this error:
>>org.zkoss.zk.ui.UiException: Cannot find the specified databind bean expression:bean.attributeA
>> at org.zkoss.zkplus.databind.DataBinder.myGetBeanWithExpression(DataBinder.java:992)
Why?
Hi
I found How do I apply annotated data-binding on a Regular Macro Component?, is this you are searching for ?
Thanks samchuang. I'll try this.
Asked: 2010-03-31 10:22:28 +0800
Seen: 582 times
Last updated: Apr 01 '10