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

IncompatibleClassChangeError when form object is null and its declared type is an interface

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Normal Normal
    • 8.5.0
    • 8.0.4
    • Databind 2
    • Security Level: Jimmy
    • None

      When the object to be proxied is null and its declared type is an interface, IncompatibleClassChangeError is thrown. It seems the declared type must always be a class which was not a requirement with ZK 7.

      public interface Concept {
        public String getCode();
        public String getDescription();
        public Concept setCode(String code);
        public Concept setDescription(String description);
      }
      
      public class BasicConcept implements Concept {
        private String code;
        private String description;
        @Override
        public String getCode() {
          return code;
        }
        @Override
        public String getDescription() {
          return description;
        }
        @Override
        public Concept setCode(String code) {
          this.code = code;
          return this;
        }
        @Override
        public Concept setDescription(String description) {
          this.description = description;
          return this;
        }
      }
      
      public class ConceptOne extends BasicConcept {
        private String propertyOne;
        public String getPropertyOne() {
          return propertyOne;
        }
        public ConceptOne setPropertyOne(String propertyOne) {
          this.propertyOne = propertyOne;
          return this;
        }
      }
      
      public class ConceptTwo extends BasicConcept {
        private String propertyTwo;
        public String getPropertyTwo() {
          return propertyTwo;
        }
        public ConceptTwo setPropertyTwo(String propertyTwo) {
          this.propertyTwo = propertyTwo;
          return this;
        }
      }
      
      public class Test {
        private List<Concept> concepts;
        private Concept selected;
        @Command
        @NotifyChange("selected")
        public void doReset(@BindingParam("form") Concept form) {
        }
        @Command
        @NotifyChange("concepts")
        public void doSave(@BindingParam("form") Concept form) {
        }
        public List<Concept> getConcepts() {
          return concepts;
        }
        public Concept getSelected() {
          return selected;
        }
        @Init
        public void init() {
          concepts = new ArrayList<>(2);
          concepts.add(new ConceptOne().setPropertyOne("Property 1").setCode("1").setDescription("Concept 1"));
          concepts.add(new ConceptOne().setPropertyOne("Property 2").setCode("2").setDescription("Concept 2"));
          selected = null;
        }
        public void setSelected(Concept selected) {
          this.selected = selected;
        }
      }
      
      <vlayout viewModel="@id('vm') @init('Test')">
        <listbox height="100px" model="@load(vm.concepts)"
          selectedItem="@bind(vm.selected)">
          <listhead>
            <listheader label="Code" />
            <listheader label="Description" />
          </listhead>
          <template name="model">
            <listitem>
              <listcell label="${each.code}" />
              <listcell label="${each.description}" />
            </listitem>
          </template>
        </listbox>
        <hlayout form="@id('fx') @load(vm.selected) @save(vm.selected, before='doSave')">
          <label value="Code" />
          <textbox constraint="no empty" instant="true" maxlength="64" value="@bind(fx.code)" disabled="@load(empty vm.selected)" />
          <label value="Description" />
          <textbox constraint="no empty" instant="true" maxlength="1000" value="@bind(fx.description)" disabled="@load(empty vm.selected)" />
          <button label="Reset" onClick="@command('doReset',form=fx)" disabled="@load(not fxStatus.dirty)" />
          <button label="Save" onClick="@command('doSave',form=fx)" disabled="@load(not fxStatus.dirty)" />
        </hlayout>
      </vlayout>
      

            bobpeng bobpeng
            benedetti benedetti
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: