@bind for macro component with custom class

asked 2015-03-25 14:01:53 +0800

viachris gravatar image viachris
27 5

updated 2015-03-25 14:15:54 +0800


i have the following problem:

I created a new macro component. It combines a textbox with a popup, that is always shown, when the textbox has focus.


    <textbox id="textbox" value="${arg.value}" width="${empty arg.width ? '98%' : arg.width}"/>
    <popup id="popup" width="200px" />

<!-- It is registered in language-addon -->

For this Macro i created a HtmlMacroComponent class:

public class MyMacro extends HtmlMacroComponent {

        private static final long serialVersionUID = 1L;

        private Textbox textbox;

        private Popup popup;

        private Label label;

        public MyMacro() {
            label = new Label();

        public void textboxFocus() {
            label.setValue("some Text");
            popup.open(textbox, "end_before");

In the .zul pages where i want to use the macro, i want to use @bind for a bean-field:


<myMacro value="@bind(vm.bean.field)" /> <!-- vm is the ViewModel Class -->

The Bean is a straightforward JPA-Entity.

My problem: the text i put into the textbox is not given to the bean (everything else works, the popup is shown and so on).

As an alternative to @ComponentAnnotation i found this: http://zkfiddle.org/sample/6sleo1/2-macro-with-manual-reference (link)

But it only works when using a macro component without a custom class. In my case i get a Property not found exception for the pojo.

I can't use @ref because we don't have PE or EE license.

Can someone help me?

ZK version is 6.5.3.

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted

answered 2015-03-26 06:46:30 +0800

chillworld gravatar image chillworld flag of Belgium
5322 4 9

updated 2015-03-27 19:22:52 +0800

Hey viachris,

Your doing it quite good but you only make a few small mistakes.

First mistake :

In the zul you have :

<textbox id="textbox" value="${arg.value}"

Don't set the value there.(in the zul)
What you are doing is only a just set the value once and nothing more.

Second mistake :

In addition of the first mistake, the value has to go to the getter and setter of value. So what you need in the Java class is :

public void setValue(String value) {

public String getValue() {
    return textbox.getValue();

public void textboxChange() {
    Events.postEvent("onEdited", this, textbox.getValue());

And normally this should work.

Hope this can help you further.

Edit for comment getting "bean.string" :

Maybe it's possible through the binder or something.
I have to look that up and try and error that.

Easy solution should be :

<myMacro value="@bind(vm.bean.field)" from="bean.field"/>

And in the class you create a getter and setter like :

private String from;

public void setFrom(String from) {
    this.from = from;

public String getFrom() {
    return from;

It's surely not the most cleanest way but it's the only way I can say directly without testing some stuff.

Greetz Chill.

link publish delete flag offensive edit


Thanks for the answer, but even with your suggested changes the content of the textbox is not given to the bean. bean.field is still empty.

viachris ( 2015-03-26 07:09:20 +0800 )edit

try this now

chillworld ( 2015-03-26 10:20:58 +0800 )edit

Where do i get the 'value' from in the postEvent method?

viachris ( 2015-03-26 15:24:44 +0800 )edit

oh excuse me, textbox.getValue(), that's the problem of not having a fiddle and just write code here :)

chillworld ( 2015-03-26 16:26:48 +0800 )edit

That's it! Thank you very much! This helpes me immensely :) Sadly i can't upvote because i don't have enough points... that's kind of silly...

viachris ( 2015-03-27 13:37:28 +0800 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

1 follower



Asked: 2015-03-25 14:01:53 +0800

Seen: 35 times

Last updated: Mar 27 '15

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