-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I am trying to get databindings working to bind to a message object that is like a java.util.Map but is not a Map. I wrote an adapter that implements Map and successfully bound a ListBox to a collection of the message objects. Now I want to have bindings write to the properties of the custom message object which look like message.put("key", value). I want the keys that are to be written to be set declaratively in the page as shown here:
<vbox id="input">
<textbox id="msg" style="width:250px" value="@{chatOut.map.msgtext,load-when='none',save-when='submit.onClick'}"/>
<hbox>
<button id="submit" label="send"/>
</hbox>
</vbox>
The binding @{chatOut.map} resolves to a java.util.Map and I was hoping that @{chatOut.map.xxx} would set the map key "xxx". This does not appear to work.
Does anyone know how to have a databinding to something like a map so that I don't have to have specific getters/setters for the object that I want to bind to?
I was thinking about using cglib or DynBeans to dynamically generate a JavaBean adapter that ZK would use java.beans.* to call setters on. Then I could intercept the calls on the dynamic JavaBean and could set them on my message. Looking at the org.zkoss.zkplus.databind package it does not use java.beans.* so it is not possible to bind onto a dynamically generated JavaBean.
> The binding @{chatOut.map} resolves to a java.util.Map and I was hoping that @{chatOut.map.xxx} would set the map key "xxx". This does not appear to work.
This should work by spec. It is a bug. Would you help post to ZK Bugs.
Regarding the dynamic JavaBean etc, we are thinking about a plugable "evaluator" kind of mechanism for next version of DataBinder, so the load/save is not limited to currently "reflection" mechanism.
Simon,
I tested the Map object in data binding and it works. Would you check this in your environment? Following is my test case:
<?page title="Test data binding a Map" contentType="text/html;charset=UTF-8"?> <?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?> <zk> <window title="Test data binding a Map" border="normal"> <zscript><![CDATA[//@IMPORT import java.util.Map; import java.util.HashMap; ]]> <![CDATA[ Map mymap = new HashMap(); ]]> </zscript> <textbox value="@{mymap.xyz}"/> <button label="see Map" onClick='alert(mymap)'/> </window> </zk>
Asked: 2009-03-01 21:37:39 +0800
Seen: 311 times
Last updated: Mar 04 '09