0

Determine the binding (the bean backing a textbox) of a component in a HtmlMacroComponent

asked 2015-03-30 14:10:48 +0800

viachris gravatar image viachris
27 5

updated 2015-03-30 14:16:19 +0800

Hello everyone,

i created a Macro-component:

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

</zk>

With a custom Java-Class, extending HtmlMacroComponent:

@ComponentAnnotation("value:@ZKBIND(ACCESS=both,SAVE_EVENT=onEdited)")    
public class MyMacro extends HtmlMacroComponent {

        private static final long serialVersionUID = 1L;

        @Wire
        private Textbox textbox;

        @Wire
        private Popup popup;

        private Label label;

        public MyMacro() {
            label = new Label();
            setMacroURI("/zul/components/myMacro.zul");
            setStyle("display:block");
            afterCompose();
            popup.appendChild(label);
        }
 @Listen("onFocus=#textbox")
        public void textboxFocus() {
            label.setValue("some Text");
            popup.open(textbox, "end_before");
        }

       public void setValue(String value) {
    textbox.setValue(value);
}

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

@Listen("onChange=#textbox")
public void textboxChange() {
    Events.postEvent("onEdited", this, textbox.getValue());
    }

}

In this HtmlMacroComponent i would like to determine the Binding, that is forwarded in the place the macro is used:

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

By this i mean the name of the bean and the field and not the content. It could be the class of the bean or the getter of the vm or anything else really, that helps me to unequivocally identify the bean and field.

To make it more clear, i'm searching for a method like:

textbox.getBinding() // Returns "field.bean" or [org.package.Bean.class, "field"] or something like that

Can someone help me with that?

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2015-03-31 03:11:15 +0800

cor3000 gravatar image cor3000
4596 2 7
ZK Team

updated 2015-03-31 03:12:09 +0800

programmatically, you can read the bind annotations directly of the components using the getAnnotation/s methods:

then the binding expression is in the 'value' attribute of that annotation (attention there can be multiple annotations!)

here a short example displaying the expression for the value of the textbox: If you have a reference to the component you can call these methods in your java code of course (this example is chosen for it's brevity):

<div apply="org.zkoss.bind.BindComposer" width="300px">
    <textbox value="@load(self.parent.width)" tooltiptext="@load(self.getAnnotation('value', 'load').getAttribute('value'))"/>
</div>
link publish delete flag offensive edit

Comments

Thank you for the answer. Because i'm using a Custom HtmlMacroComponent with @ComponentAnnotation("value:@ZKBIND(ACCESS=both,SAVE_EVENT=onEdited)") the access isn't like described in the Javadoc. When calling textbox.getAnnotations("value") i get the following annotations: (see next answer)

viachris ( 2015-03-31 07:25:52 +0800 )edit

[@ZKBIND(ACCESS=[both], SAVEEVENT=[onChange], LOADREPLACEMENT=[rawValue], LOAD_TYPE=[java.lang.String]), @default-bind(access=[both], save-when=[self.onChange])]

viachris ( 2015-03-31 07:26:00 +0800 )edit

I found it! I had to use getAnnotation on the parent of the textbox (the macro)! Thanks!

viachris ( 2015-03-31 07:37:39 +0800 )edit
2

answered 2015-03-31 03:09:26 +0800

echarish gravatar image echarish flag of Japan
1809 7
http://jp.linkedin.com/in...

There is a very good example available http://books.zkoss.org/wiki/ZKDeveloper%27sReference/UIComposing/MacroComponent/ImplementCustomJava_Class

for passing the binding from the parent page, refer to the end part of the link page where it says Manipulate component inside macro component

I hope it will help you to resolve your task, if not do let us know if you need more help.

link publish delete flag offensive edit

Comments

Thanks for you answer. The passing of the binding is not the problem. I want to retrieve the binded bean and the specific field in which the value is saved within the Custom HtmlMacroComponent. For example: when i use "<myMacro value="@bind(vm.bean.field)" />" i want to know (see next answer)

viachris ( 2015-03-31 07:31:03 +0800 )edit

...the name of the bean-class and the specific field theat is binded.

viachris ( 2015-03-31 07:31:43 +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

Follow
1 follower

RSS

Stats

Asked: 2015-03-30 14:10:48 +0800

Seen: 47 times

Last updated: Mar 31 '15

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