Menu

#530 DataBinder support binding to Map

closed
nobody
None
5
2007-12-01
2007-08-03
No

It seams that we can use data binding only with the properties of a Javabean.
How about binding to Map entries using the map keys as the property name?
And it should be great if we could bind to Jakarta DynaBeans too.

Andrea Mattioli

Discussion

  • Henri Chen

    Henri Chen - 2007-12-01
    • summary: Binding to Maps and DynaBeans --> DataBinder support binding to Map
     
  • Henri Chen

    Henri Chen - 2007-12-01

    Logged In: YES
    user_id=89247
    Originator: NO

    It might not proper to support directly in the ZK data binder code the Apache DynaBeans. Unless we figure out a plugin that we can plugin a support of such kind. So I change the feature request Summary to "DataBinding support binding to Map.

     
  • Henri Chen

    Henri Chen - 2007-12-01

    Logged In: YES
    user_id=89247
    Originator: NO

    Testing code
    ----------

    <?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?>
    <window id="mainwin">
    <zscript>
    import org.zkoss.lang.Objects;
    Map mymap = new HashMap();
    mymap.put("firstName", "John");
    mymap.put("lastName", "Chang");
    </zscript>
    <textbox value="@{mymap.firstName}"/>
    <textbox value="@{mymap.lastName}"/>
    <button label="Map Internal" onClick="alert(Objects.toString(mymap))"/>
    </window>

     
  • Henri Chen

    Henri Chen - 2007-12-01
    • status: open --> closed
     
  • Henri Chen

    Henri Chen - 2007-12-01

    Logged In: YES
    user_id=89247
    Originator: NO

    Ready since 12/1.

     
  • kato

    kato - 2008-02-05

    Logged In: YES
    user_id=1642517
    Originator: NO

    The implementation first tries to bind as a bean, then upon exception tries as a map. I will be using only maps. This means an exception every time. Would it not be better to check if the bean is a map first? Like this:

    if (bean instanceof Map) {
    bean = ((Map)bean).get(nodeid);
    } else {
    try {
    bean = Fields.get(bean, nodeid);
    } catch (NoSuchMethodException ex) {
    throw UiException.Aide.wrap(ex);
    }
    }

    This would be more efficient.

     
  • Henri Chen

    Henri Chen - 2008-02-13

    Logged In: YES
    user_id=89247
    Originator: NO

    Agree. Thanks for the suggestion. I will refactor codes in next release.

     
  • Henri Chen

    Henri Chen - 2008-02-13

    Logged In: YES
    user_id=89247
    Originator: NO

    After the second thought. What if the implemented Map got some getXxx() and setXxx() methods? With the new way suggested, these getters and setters will not be called at all.

    Has to think it thru first...

     

Log in to post a comment.