Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-4509

Setting model in onOpen listener of combobox causes "... cannot be cast to org.zkoss.zul.Comboitem" error



    • Bug
    • Resolution: Fixed
    • Normal
    • 9.6.1
    • 9.0.0, 8.6.3, 8.6.4
    • None
    • Security Level: Jimmy


      Currently in our application (using ZK EE 7.0.5), for comboboxes we set the model in an onOpen listener so that the drop down list is always sourced from live data when the user opens the list. Also, in some cases the list may be restricted based on the values of other fields on the same page.

      We are trying to upgrade to ZK 8 and have been testing on ZK EE 8.6.3.

      We have a number of pages where a value selected from a combobox is used to limit records displayed in a listbox or grid. When using ZK 8 (8.6.3 or 8.6.4) or 9 (9.0.0), some of these pages will return a "{component} cannot be cast to org.zkoss.zul.Comboitem" at org.zkoss.zul.Combobox.service(Combobox.java:990). In some cases the error message can be reproduced consistently.

      Use attached zul and java files and the following steps to reproduce the error.

      1. Open test.zul
      2. Using the mouse drop down the category list and select "Category 2". The list below should now have 20 rows.
      3. Using the mouse drop down the category list and select "Category 3". The list below should be empty.
      4. Repeat step 2. An error message should appear see attached zk_combobox_error.png

      If the error message does not appear then increasing Category 2 list size (e.g. 200 instead of 20) then clicking the "Regenerate lists" button and repeating steps 2 to 4 may help.

      Debugging the code revealed that at line 990 Combobox.service was attempting to set the prevSeld to the listcell as noted in attached zk_combobox_list.png

      Note that, for pages in our application, the {component} which cannot be cast to org.zkoss.zul.Comboitem varies depending on what is displayed on the page (e.g. org.zkoss.zul.Hlayout, org.zkoss.zul.Label, org.zkoss.zul.Listcell, org.zkoss.zul.Listitem, org.zkoss.zul.Row)

      Note that this issue does not occur in ZK EE 7.0.5. We have not attempted to reproduced this issue in ZK 8 versions prior to 8.6.3.

      Current Result

      java.lang.ClassCastException: class org.zkoss.zul.Listcell cannot be cast to class org.zkoss.zul.Comboitem (org.zkoss.zul.Listcell and org.zkoss.zul.Comboitem are in unnamed module of loader 'app')
      	at org.zkoss.zul.Combobox.service(Combobox.java:990)
      	at org.zkoss.zk.ui.impl.DesktopImpl.service(DesktopImpl.java:792)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execUpdate(UiEngineImpl.java:1318)
      	at org.zkoss.zk.au.http.DHtmlUpdateServlet.process(DHtmlUpdateServlet.java:611)
      	at org.zkoss.zk.au.http.DHtmlUpdateServlet.doGet(DHtmlUpdateServlet.java:487)
      	at org.zkoss.zk.au.http.DHtmlUpdateServlet.doPost(DHtmlUpdateServlet.java:495)





        1. test.zul
          1.0 kB
        2. TestCombobox.java
          2 kB
        3. TestVM.java
          2 kB
        4. zk_combobox_error.png
          6 kB
        5. zk_combobox_list.png
          39 kB

        Issue Links



              Leon03 Leon03
              Andrew69 Andrew69
              0 Vote for this issue
              5 Start watching this issue