0

Data Binding on Macro Components, what's is the best way to do?

asked 2010-03-31 10:22:28 +0800

fmcypriano gravatar image fmcypriano
612 1 7
http://felipecypriano.com...

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,

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2010-03-31 13:08:15 +0800

fmcypriano gravatar image fmcypriano
612 1 7
http://felipecypriano.com...

updated 2010-03-31 13:09:47 +0800

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?

link publish delete flag offensive edit

answered 2010-03-31 19:33:05 +0800

samchuang gravatar image samchuang
4084 4

Hi

I found How do I apply annotated data-binding on a Regular Macro Component?, is this you are searching for ?

link publish delete flag offensive edit

answered 2010-04-01 07:22:10 +0800

fmcypriano gravatar image fmcypriano
612 1 7
http://felipecypriano.com...

Thanks samchuang. I'll try this.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2010-03-31 10:22:28 +0800

Seen: 582 times

Last updated: Apr 01 '10

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More