0

Problem binding values to a composite component

asked 2013-01-28 19:07:33 +0800

spitghost gravatar image spitghost
1

Problem binding values to a composite component

Hey all,

I'm developing a composite component and I'm trying to bind a property to a textbox inside my component. I've read a few articles about the subject and spend a few hours arround this situation and I still get the same problem...the bind only works in one way. By saying this I mean that when the object is loaded everything works fine, but when the value of the textbox the property value doesn't change. I've spent some time debugging and I found that everytime that the variable is about to be set after my event been thrown, the String that reaches that point is not the same as the one I've typed in the textbox.

This is how call the component:

<contactinput value="@bind(contact.contactValue)" />

This is the .zul of my composite component:

    <?component name="addremove" extends="hbox" class="AddRemoveComponent"?>
<zk>

    <hbox>
        <vbox>
            <combobox id="propertiesCombobox"
                mold="rounded" readonly="true"
                width="80px">
                <template name="model" var="property">
                    <comboitem label="property" />
                </template>
            </combobox>
        </vbox>
        <vbox>
            <textbox id="propertyValue"
                width="160px" sclass="property-value-margin" />
        </vbox>
        <vbox>
            <addremove id="addRemove" plusButtonVisible="true"
                minusButtonVisible="true" sclass="addremove-margin" />
        </vbox>
    </hbox>
</zk>

And this is the java related to my component:

public class ContactInputComponent extends Hbox implements IdSpace {

    private static final String COMPONENT_PATH = "/common/contact_input_component.zul";

    private static final String ON_BLUR_VALUE = "onBlurValue";

 @Wire
    private Textbox propertyValue;

public ContactInputComponent() {
        this.buildContactInputComponent();
    }

    public ContactInputComponent(Component[] children) {
        super(children);
        this.buildContactInputComponent();

    }

private void buildContactInputComponent() {
        Executions.createComponents(COMPONENT_PATH, this, null);
        Selectors.wireVariables(this, this, null);
        Selectors.wireComponents(this, this, false);
        Selectors.wireEventListeners(this, this);
    }

@ComponentAnnotation("value:@ZKBIND(ACCESS=both, SAVE_EVENT=onEdited)")
    public String getValue() {
        return this.value;
    }

    public void setValue(String value) {
        this.value = value;
        this.propertyValue.setValue(this.value);
    }

@Listen("onBlur = #propertyValue")
    public void onBlurPropertyValue() {
        System.out.println("Box:" + this.propertyValue.getValue());
        Events.sendEvent("onEdited", this, null);
        Events.sendEvent(new OnBlurPropertyValue(this.propertyValue.getValue(), this));
    }

 public static class OnBlurPropertyValue extends Event {

        public OnBlurPropertyValue(String input, Component target) {
            super(ON_BLUR_VALUE, target, input);
        }

    }
}

Can anyone help me by explaining me what am I doing wrong for the "set" part of binding don't work?

Thanks in advance

delete flag offensive retag edit

Comments

Can it possible for you to share demo war file so that i can tell you what the issue

sjoshi ( 2013-01-29 04:42:54 +0800 )edit

sjoshi I've found the problem...it was missing a line in onBlurPropertyValue() that clearly stated that my value property was related to the textbox value. I havn't posted a response yet because since i'm a newbie here I need to wait one day more. Thanks for your attention!

spitghost ( 2013-01-29 11:24:53 +0800 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2013-02-01 10:13:23 +0800

spitghost gravatar image spitghost
1

Hey all,

I'm sorry for such a late answer, but due to the resctrictions imposed by my newbie state in here this was the only option availble. I've found the solution for my problem...apparently it was missing a line in public void onBlurPropertyValue() that set my value with the value that is in the textbox.

this.value = this.propertyValue.getValue();

Hope it helps!

link publish delete flag offensive 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
3 followers

RSS

Stats

Asked: 2013-01-28 19:07:33 +0800

Seen: 73 times

Last updated: Feb 01 '13

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