0

Exception for the selectedItem of a custom macro based on a combobox (Cannot convert <Comboitem o2EQdh> of type class java.lang.String to class org.zkoss.zul.Comboitem)

asked 2015-03-31 10:25:44 +0800

viachris gravatar image viachris
27 5

updated 2015-03-31 10:28:00 +0800

Hello everyone.

I created a macro component, that is basically a custom combobox that shows a message on focus.

The myCombobox.zul:

<zk>
    <combobox id="combobox" width="${empty arg.width ? '98%' : arg.width}" model="${arg.model}" mold="default" readonly="true" errorMessage="@load(vmsgs[self.parent])" />
</zk>

I use a custom java-class for it that implements HtmlMacroComponent:

@ComponentAnnotation({ "value:@ZKBIND(ACCESS=load,SAVE_EVENT=onEdited)", "selectedItem:@ZKBIND(ACCESS=both,SAVE_EVENT=onEdited)",
        "model:@ZKBIND(ACCESS=load,SAVE_EVENT=onEdited)" })
public class WegeCombobox extends HtmlMacroComponent {

    private static final long serialVersionUID = 1L;

    @Wire
    private Combobox combobox;

    public WegeCombobox() {
        setMacroURI("/zul/components/myCombobox.zul");
        setStyle("display:block");
        afterCompose();
    }

    @Listen("onFocus=#combobox")
    public void comboboxFocus() {
        Clients.showNotification("Some text",
                Clients.NOTIFICATION_TYPE_INFO, combobox, "end_before", 3000, true);
    }

    @Listen("onCreate=#combobox")
    public void comboboxCreate() {
        setModel((ArrayList<?>) getDynamicProperty("model"));
    }

    public void setValue(String value) {
        combobox.setValue(value);
    }

    public String getValue() {
        return combobox.getValue();
    }

    public void setSelectedItem(Comboitem fo) {
        combobox.setSelectedItem(fo);
    }

    public Comboitem getSelectedItem() {
        return combobox.getSelectedItem();
    }

    @SuppressWarnings({ "rawtypes", "unchecked" })
    public void setModel(ArrayList<?> model) {
        combobox.setModel(new ListModelList(model, true));
    }

    public ListModel<?> getModel() {
        return combobox.getModel();
    }


    @Listen("onChange=#combobox")
    public void comboboxChange() {
        Events.postEvent("onEdited", this, combobox.getSelectedItem());
        Events.postEvent("onEdited", this, combobox.getValue());
    }

}

I use it in my webpages like this:

<myCombobox id="myCB" selectedItem="@load(vm.bean.foo) @save(vm.bean.foo, before={'command1','command2'}) @validator('beanValidator')" value="@load(vm.bean.foo)" model="@bind(vm.someStringValuesAsArrayList)" />

After submitting the form i get the following error:

org.zkoss.zk.ui.UiException: Cannot convert <Comboitem o2EQdh> of type class java.lang.String to class org.zkoss.zul.Comboitem at [file:/zul/somePage.zul, line:54]
org.zkoss.zk.ui.UiException: Cannot convert <Comboitem o2EQdh> of type class java.lang.String to class org.zkoss.zul.Comboitem at [file:/zul/somePage.zul, line:54]
    at org.zkoss.bind.impl.MiscUtil.mergeExceptionInfo(MiscUtil.java:175)
    at org.zkoss.bind.impl.BindEvaluatorXImpl.setValue(BindEvaluatorXImpl.java:58)
    at org.zkoss.bind.impl.LoadPropertyBindingImpl.load(LoadPropertyBindingImpl.java:91)
    at org.zkoss.bind.impl.BinderImpl.doPropertyChange0(BinderImpl.java:388)
    at org.zkoss.bind.impl.BinderImpl.doPropertyChange(BinderImpl.java:365)
    at org.zkoss.bind.impl.BinderImpl.access$100(BinderImpl.java:106)
    at org.zkoss.bind.impl.BinderImpl$QueueListener.onEvent(BinderImpl.java:290)
    at org.zkoss.zk.ui.event.impl.DesktopEventQueue$QueueListener.onEvent(DesktopEventQueue.java:145)
    at org.zkoss.zk.ui.AbstractComponent.onEvent(AbstractComponent.java:2742)
    at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2713)
    at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2654)
    at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:136)
    at org.zkoss.zk.ui.impl.UiEngineImpl.processEvent(UiEngineImpl.java:1717)
    at org.zkoss.zk.ui.impl.UiEngineImpl.process(UiEngineImpl.java:1502)
    at org.zkoss.zk.ui.impl.UiEngineImpl.execUpdate(UiEngineImpl.java:1212)
    at org.zkoss.zk.au.http.DHtmlUpdateServlet.process(DHtmlUpdateServlet.java:600)
    at org.zkoss.zk.au.http.DHtmlUpdateServlet.doGet(DHtmlUpdateServlet.java:482)
    at org.zkoss.zk.au.http.DHtmlUpdateServlet.doPost(DHtmlUpdateServlet.java:491)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)
Caused by: org.zkoss.zel.ELException: Cannot convert <Comboitem o2EQdh> of type class java.lang.String to class org.zkoss.zul.Comboitem
    at org.zkoss.zel.impl.lang.ELSupport.coerceToTypeForSetValue(ELSupport.java:485)
    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:55)
    ... 37 more

How can i fix this: "Cannot convert <comboitem o2eqdh=""> of type class java.lang.String to class org.zkoss.zul.Comboitem" ?

delete flag offensive retag edit

Comments

use a <template> in your custom component.

chillworld ( 2015-03-31 10:58:38 +0800 )edit

Hello again! Could you elaborate further? I don't know if it is applicable here, because in the macro component i don't know the name of the field that is used in the @load of the label of one comboitem: <comboitem value="@bind(each)" label="@load(the macro component doesn't know the field)"/>

viachris ( 2015-03-31 12:05:16 +0800 )edit

And i get this error when using a template: java.lang.String cannot be cast to org.zkoss.zul.Comboitem. I use it like this: <template name="model"> <comboitem value="@bind(each)" /> </template> (the combobox stays the same)

viachris ( 2015-03-31 12:08:55 +0800 )edit

normally it should be value=${each} or with @load. Then should the comboItem select the String for selectedItem. Otherwise, try to create a zk fiddle where I can work on. This is easier for me and I adapt it directly to the corrected code.

chillworld ( 2015-03-31 12:38:09 +0800 )edit

I think i have to work with a converter: http://www.zkoss.org/javadoc/latest/zk/org/zkoss/bind/converter/sys/ComboboxSelectedItemConverter.html But the standard converter only works with standard Comboboxes and throws a ClassCastException (cannot cast myCombobox to Combobox).I'll try to implement it

viachris ( 2015-03-31 14:25:40 +0800 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2015-03-31 15:00:48 +0800

viachris gravatar image viachris
27 5

updated 2015-03-31 15:02:18 +0800

I found the answer:

I had to implement my own Converter (basically a copy of the ComboboxSelectedItemConverter) and give it to the HtmlMacroComponent:

@ComponentAnnotation({"value:@ZKBIND(ACCESS=load,SAVE_EVENT=onEdited)", "selectedItem:@ZKBIND(ACCESS=both,SAVE_EVENT=onEdited,CONVERTER=org.myPackage.MySelectedItemConverter)", "model:@ZKBIND(ACCESS=load,SAVE_EVENT=onEdited)"})
link publish delete flag offensive edit
0

answered 2015-04-01 09:51:33 +0800

chillworld gravatar image chillworld flag of Belgium
5367 4 9
https://github.com/chillw...

Hey viachris.

I worked out a working fiddle for you.

I do not know why you need the selected item seperatly cause this is the value no?
If you need the selectedItem, please give me information why you need it.

Greetz Filip

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
1 follower

RSS

Stats

Asked: 2015-03-31 10:25:44 +0800

Seen: 57 times

Last updated: Apr 01 '15

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