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

listmodel.setMultiple not behaving consistently with javadocs

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reviewing
    • Priority: Normal
    • Resolution: Unresolved
    • Affects Version/s: 8.6.1
    • Fix Version/s: 9.5.0.1
    • Component/s: Components, JavaDoc
    • Labels:
      None

      Description

      Steps to Reproduce

      run the code, compare the 2 listboxes

      <zk>
          <listbox id="lb1" multiple="true"/>
          <zscript><![CDATA[
              ListModelList model = new ListModelList();
              model.add("aaa"); model.add("bbb"); model.add("ccc");
      
              lb1.setModel(model);
              lb1.setCheckmark(true);
              lb1.setMultiple(true);
          ]]></zscript>
      
          <listbox id="lb2"/>
          <zscript><![CDATA[
              ListModelList model = new ListModelList();
              model.add("aaa"); model.add("bbb"); model.add("ccc");
      
              lb2.setModel(model);
              lb2.setCheckmark(true);
              lb2.setMultiple(true);
          ]]></zscript>
      </zk>
      

      Current Result

      lb1 -> radio buttons (single selection)
      lb2 -> check boxes (multiple selection)

      Expected Result

      consistent results / documentation:

      According to the javadocs ...
      https://www.zkoss.org/javadoc/latest/zk/org/zkoss/zul/Listbox.html#setMultiple-boolean-
      ... setting/changing multiple is allowed when using a model.
      -> both listboxes should render with multiple selection

      The Component Reference states something different:
      https://www.zkoss.org/wiki/ZK%20Component%20Reference/Data/Listbox#Enable_with_a_ListModel
      (which also makes sense, since setting the model later overrides previous settings to)

      A similar hint from the javadocs of Listbox:

      [Since 6.0.0] If a model is set, whether the listbox allows the multiple selection depends on Selectable.setMultiple(boolean). In other words, the application shall not access listbox directly if a model is assigned. Rather, the application shall access the model directly.

      Debug Info

      Root Cause

      https://github.com/zkoss/zk/blob/master/zul/src/org/zkoss/zul/Listbox.java#L766
      For lb1 the call into the list model is ignored, since the multiple property has already been set from the zul file, and hasn't changed by applying the model.

      Workaround (Recommended Usage)

      use setMultiple on the listmodel when using a list model

        Attachments

          Activity

            People

            Assignee:
            katherinelin katherinelin
            Reporter:
            cor3000 cor3000
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:

                Time Tracking

                Estimated:
                Original Estimate - 1 day, 4 hours
                1d 4h
                Remaining:
                Remaining Estimate - 1 day, 4 hours
                1d 4h
                Logged:
                Time Spent - Not Specified
                Not Specified