0

DataBinder binding to something that you cannot reflect upon

asked 2009-03-01 21:37:39 +0800

simonmassey gravatar image simonmassey
90 1

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.

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2009-03-02 01:43:00 +0800

henrichen gravatar image henrichen
3869 2
ZK Team

> 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.

link publish delete flag offensive edit

answered 2009-03-04 06:25:24 +0800

henrichen gravatar image henrichen
3869 2
ZK Team

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>

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: 2009-03-01 21:37:39 +0800

Seen: 311 times

Last updated: Mar 04 '09

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