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

overriding zkbind listbox model converter doesn't work

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • 8.6.1
    • 8.6.0
    • None
    • Security Level: Jimmy

      Steps to Reproduce

      1. put a lang-addon.xml under maven project resources/metainfo/zk/

      <?xml version="1.0" encoding="UTF-8"?>
      <language-addon>
          <addon-name>myaddon</addon-name>
          <language-name>xul/html</language-name>
          <depends>zkbind</depends>
          <component>
              <component-name>listbox</component-name>
              <extends>listbox</extends>
              <annotation>
                  <annotation-name>ZKBIND</annotation-name>
                  <property-name>model</property-name>
                  <attribute>
                      <attribute-name>CONVERTER</attribute-name>
                      <attribute-value>org.zkoss.mvvm.MyListboxConverter</attribute-value>
                  </attribute>
              </annotation>
          </component>
      </language-addon>
      

      2. run the attached zul

      Current Result

      a listbox still use the default system converter

      Expected Result

      a listbox should run with MyListboxConverter

      Debug Information

      • this doesn't happen on 8.5.2.1
      • in AnnotationUtil.java
        	public static Annotation getSystemAnnotation(ComponentCtrl compCtrl, String propName) {
        		...
        		//Use custom ZKBIND annotation instead of default ZKBIND annotation if any
        		if (annos instanceof List) {
        			return (Annotation) ((List) annos).get(0);
        		}
        

        but the custom convert specified in lang-addon.xml is the last item in annos

      workaround

      import org.zkoss.bind.Binder;
      import org.zkoss.zk.ui.WebApp;
      import org.zkoss.zk.ui.metainfo.*;
      import org.zkoss.zk.ui.util.WebAppInit;
      
      import java.util.*;
      
      public class MyWebInit implements WebAppInit {
          @Override
          public void init(WebApp wapp) throws Exception {
              Collection<Annotation> annotations = LanguageDefinition.lookup(null).getComponentDefinition("listbox")
                      .getAnnotationMap().getAnnotations("model", Binder.ZKBIND);
              if (annotations.size() > 1) {
                  Iterator iterator = annotations.iterator();
                  iterator.next();
                  iterator.remove();
              }
          }
      }
      

      apply the above listener in zk.xml .

        1. MyListboxConverter.java
          0.2 kB
        2. listbox.zul
          0.4 kB
        3. ItemsVM.java
          0.5 kB

            rudyhuang rudyhuang
            hawk hawk
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 4 hours
                4h
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 4 hours
                4h