Revision history [back]

click to hide/show revision 1
initial version

asked 2017-04-03 16:55:17 +0800

trapongx gravatar image trapongx

Custom component that extends Textbox does not fire onChange event

I tried to create a very simple custom text by extending existing Textbox component. The component displayed correctly with bound value. The problem is, when I make change to the input, the browser does not fire onChange event to the server-side. Is this a bug or am I doing something wrong?

This is my code in lang-addon.xml

<language-addon>
    <addon-name>myzkcomp</addon-name>
      <version>
      <version-class>net.bitreplay.Version</version-class>
      <version-uid>1.0-SNAPSHOT</version-uid>
      <zk-version>8.0.2.2</zk-version>
  </version>

  <language-name>xul/html</language-name>

  <component>
      <component-name>jpatextbox</component-name>
      <component-class>net.bitreplay.JpaTextbox</component-class>
      <extends>textbox</extends>
  </component>
</language-addon>

in index.zul

<zk>
  <window title="Hello World!!" border="normal" width="300px"
      apply="org.zkoss.bind.BindComposer"
      viewModel="@id('vm') @init('test.ctrl.MyVm')">
      <jpatextbox value="@bind(vm.name)"/>
  </window>
</zk>

in MyVm.java

package test.ctrl;

public class MyVm {
    private String name = "Hooray";

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

in Version.java

package net.bitreplay;

public class Version {
  public static final String UID = "1.0-SNAPSHOT";
}

I tried the same thing with Intbox and Combobox. They give me the same problem.

This show the version of ZK I'm using via Gradle build

 compile("org.zkoss.zk:zkbind:8.0.2.2")
 compile("org.zkoss.zk:zul:8.0.2.2")
 compile("org.zkoss.zk:zuti:8.0.2.2-Eval")
 compile("org.zkoss.zk:zkmax:8.0.2.2-Eval")
 compile("org.zkoss.zk:zkex:8.0.2.2-Eval")
 compile("org.zkoss.zk:zkplus:8.0.2.2")
 compile("org.zkoss.zk:zhtml:8.0.2.2")
 compile("org.zkoss.zk:zkspring-core:3.2.0")

Custom component that extends Textbox does not fire onChange event

I tried to create a very simple custom text by extending existing Textbox component. The component displayed correctly with bound value. The problem is, when I make change to the input, the browser does not fire onChange event to the server-side. Is this a bug or am I doing something wrong?

This is my code in lang-addon.xml

<language-addon>
   <addon-name>myzkcomp</addon-name>
     <version>
      <version-class>net.bitreplay.Version</version-class>
      <version-uid>1.0-SNAPSHOT</version-uid>
      <zk-version>8.0.2.2</zk-version>
  </version>

  <language-name>xul/html</language-name>

  <component>
      <component-name>jpatextbox</component-name>
      <component-class>net.bitreplay.JpaTextbox</component-class>
      <extends>textbox</extends>
  </component>
</language-addon>

in index.zul

<zk>
  <window title="Hello World!!" border="normal" width="300px"
      apply="org.zkoss.bind.BindComposer"
      viewModel="@id('vm') @init('test.ctrl.MyVm')">
      <jpatextbox value="@bind(vm.name)"/>
  </window>
</zk>

in MyVm.java

package test.ctrl;

public class MyVm {
    private String name = "Hooray";

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

in Version.java

package net.bitreplay;

public class Version {
  public static final String UID = "1.0-SNAPSHOT";
}

I tried the same thing with Intbox and Combobox. They give me the same problem.

This show the version of ZK I'm using via Gradle build

 compile("org.zkoss.zk:zkbind:8.0.2.2")
 compile("org.zkoss.zk:zul:8.0.2.2")
 compile("org.zkoss.zk:zuti:8.0.2.2-Eval")
 compile("org.zkoss.zk:zkmax:8.0.2.2-Eval")
 compile("org.zkoss.zk:zkex:8.0.2.2-Eval")
 compile("org.zkoss.zk:zkplus:8.0.2.2")
 compile("org.zkoss.zk:zhtml:8.0.2.2")
 compile("org.zkoss.zk:zkspring-core:3.2.0")

Custom component that extends Textbox does not fire onChange event

I tried to create a very simple custom text by extending existing Textbox component. The component displayed correctly with bound value. The problem is, when I make change to the input, the browser does not fire onChange event to the server-side. Is this a bug or am I doing something wrong?

This is my code in lang-addon.xml

<language-addon>
  <addon-name>myzkcomp</addon-name>
    <version>
      <version-class>net.bitreplay.Version</version-class>
      <version-uid>1.0-SNAPSHOT</version-uid>
      <zk-version>8.0.2.2</zk-version>
  </version>

  <language-name>xul/html</language-name>

  <component>
      <component-name>jpatextbox</component-name>
      <component-class>net.bitreplay.JpaTextbox</component-class>
      <extends>textbox</extends>
  </component>
</language-addon>

in index.zul

<zk>
  <window title="Hello World!!" border="normal" width="300px"
      apply="org.zkoss.bind.BindComposer"
      viewModel="@id('vm') @init('test.ctrl.MyVm')">
      <jpatextbox value="@bind(vm.name)"/>
  </window>
</zk>

in MyVm.java

package test.ctrl;

public class MyVm {
    private String name = "Hooray";

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

in Version.java

package net.bitreplay;

public class Version {
  public static final String UID = "1.0-SNAPSHOT";
}

I tried the same thing with Intbox and Combobox. They give me the same problem.

This show the version of ZK I'm using via Gradle build

 compile("org.zkoss.zk:zkbind:8.0.2.2")
 compile("org.zkoss.zk:zul:8.0.2.2")
 compile("org.zkoss.zk:zuti:8.0.2.2-Eval")
 compile("org.zkoss.zk:zkmax:8.0.2.2-Eval")
 compile("org.zkoss.zk:zkex:8.0.2.2-Eval")
 compile("org.zkoss.zk:zkplus:8.0.2.2")
 compile("org.zkoss.zk:zhtml:8.0.2.2")
 compile("org.zkoss.zk:zkspring-core:3.2.0")

---- Update ----

Hi chillworld. The system require me to wait for 2 days before I can add answer to my own question so I edit the question to put it.

Sorry, I thought I provided the code for the component already. This is it

package net.bitreplay;

import org.zkoss.zul.Textbox;

public class JpaTextbox extends Textbox {
}

binding_annotation_for_a_custom_component (I have not enough karma to post the link, please google it). I tried adding this annotation to the JpaTextbox class.

@ComponentAnnotation("value:@ZKBIND(ACCESS=both, SAVE_EVENT=onChange)")

And it works for me. However, it would be very helpful if anyone could kindly explain me why the built-in component "org.zkoss.zul.Textbox" work well without having to have the binding definition in such form of annotation nor in lang.xml (I've looked in the definition of parent classes of Textbox also). Is it just because JpaTextbox is custom so it need different ceremony?

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