0

Converter with mvvm

asked 2013-01-19 18:40:13 +0800

dmrzh3 gravatar image dmrzh3
25 2

updated 2013-01-22 06:07:48 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

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?

delete flag offensive retag edit

2 Answers

Sort by » oldest newest most voted
1

answered 2013-01-19 19:49:23 +0800

dmrzh3 gravatar image dmrzh3
25 2

updated 2013-01-22 06:13:44 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

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>
link publish delete flag offensive edit
0

answered 2013-01-22 08:39:11 +0800

dennis gravatar image dennis
3679 1 6
http://www.javaworld.com....

updated 2013-01-22 08:43:05 +0800

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.

link publish delete flag offensive edit
Your answer
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: 2013-01-19 18:40:13 +0800

Seen: 134 times

Last updated: Jan 22 '13

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