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.
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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:
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...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
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>
Logged In: YES
user_id=89247
Originator: NO
Ready since 12/1.
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.
Logged In: YES
user_id=89247
Originator: NO
Agree. Thanks for the suggestion. I will refactor codes in next release.
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...