-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I try add converter to combobox:
<combobox model="@bind(cvm.contactTypes)" selectedItem="@bind(cvm.currentContact.contactType) @converter(cvm.typeConverter)">
</combobox>
converter convert value to string:
public Object coerceToUi(Object beanProp, Component c, BindContext ctx) {
if(beanProp==null){
return "";
}
return properties.getProperty(((Enum)beanProp).name());
}
but framework throw Exception
Jan 19, 2013 9:28:28 PM org.zkoss.zk.ui.impl.UiEngineImpl handleError:1352 SEVERE:
org.zkoss.zel.ELException: Cannot convert Сотовый телефон of type class java.lang.String to class org.zkoss.zul.Comboitem at org.zkoss.zel.impl.lang.ELSupport.coerceToTypeForSetValue(ELSupport.java:468) at org.zkoss.zel.impl.parser.AstValue.setValue(AstValue.java:245) at org.zkoss.zel.impl.ValueExpressionImpl.setValue(ValueExpressionImpl.java:256) at org.zkoss.xel.zel.ELXelExpression.setValue(ELXelExpression.java:50) at org.zkoss.bind.impl.BindEvaluatorXImpl.setValue(BindEvaluatorXImpl.java:51) at org.zkoss.bind.impl.LoadPropertyBindingImpl.load(LoadPropertyBindingImpl.java:81) at org.zkoss.bind.impl.BinderImpl.loadOnPropertyChange(BinderImpl.java:360) at org.zkoss.bind.impl.BinderImpl.access$100(BinderImpl.java:98) at org.zkoss.bind.impl.BinderImpl$QueueListener.onEvent(BinderImpl.java:278) at org.zkoss.zk.ui.event.impl.DesktopEventQueue$QueueListener.onEvent(DesktopEventQueue.java:145)
How to fix this Exception?
I find solution:
<combobox model="@bind(cvm.contactTypes)" selectedItem="@bind(cvm.currentContact.contactType)">
<template name="model" var="cType">
<comboitem value="@load(cType)" label="@load(cType) @converter(cvm.typeConverter)"/>
</template>
</combobox>
zkbind2 has default converter to convert selectedItem and selectedItems (they are components in component side, however is object in viewmodel side), so, you don't need to write a converter to convert it.
here is the default converters.
If you write a conveter, it will override the default one, and then you have to transfer it between model object and selected listitems or model-selection in converter.
Asked: 2013-01-19 18:40:13 +0800
Seen: 134 times
Last updated: Jan 22 '13