MVVM automatic validation message binding

asked 2016-09-02 09:12:40 +0800

FlorianSchaetz gravatar image FlorianSchaetz flag of Germany
31 6

updated 2016-09-02 16:05:24 +0800

I've got a Macrocomponent that combines a label, a textbox and an error label...

<mycomponent id="productname" caption="Product name" value="Apple XYZ" error=""/>

...and now I want to use that for binding...

Obviously I could write...

<mycomponent id="productname" caption="Product name" value="@bind(vm.productName)" error="@bind(vmsgs['productname'])"/>

(given, of course, a validationMessages="@id('vmsgs') somewhere above and the apropriate binding annotations in the java code. All of this is already in place.)

...but of course, I would have to do this for each field and it would clutter my .zul files. So, is there any chance to somehow, perhaps even in java code, to tell the component to bind itself to vmsgs with the components id, without having to give that for every field? So that this would have the same effect...

<mycomponent id="productname" caption="Product name" value="@bind(vm.productName)"/>

..or perhaps

<mycomponent id="productname" caption="Product name" value="@bind(vm.productName)" bindError="true"/>

Of course, the component should stay usable in a non-MVVM environment, so adding fixed bindings is probably out. Any chance, for example, to find out in Java if we are bound somehow and add our own binding automatically?

To sumarize: I can already bind everything, no problem there. What I want to remove is the need of having to write explicitly error="@bind(vmsgs['productname'])" - this should somehow happen automatically.

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted

answered 2016-09-02 17:07:08 +0800

chillworld gravatar image chillworld flag of Belgium
5337 4 9

I don't have tested it but when you have the Binder you could use addChildrenLoadBindings.

Of course now getting the binder :


Just see that you can do it in the correct order and it should work.

Greetz chill.

link publish delete flag offensive edit


I had some sucess with @ComponentAnnotation("@bind(vmsgs['keyword'])"), which only has the "problem", that the component that goes into the validation is the macro component, not the specific subcomponent, so the only "key" I get is not the sub-component id, but the ViewModel's property...

FlorianSchaetz ( 2016-09-02 18:26:46 +0800 )edit

Did you try tot reach the binder in aftercompose? Normally then you could add the binding to the correct component.

chillworld ( 2016-09-02 18:38:16 +0800 )edit

It works for one macrocomponent, but as soon as I stack them in another, bigger mc, that one becomes the "source" for the validator, which means that I cannot (easily) have multiple "values" in one mc without some naming convention - instead of simply relying on id.

FlorianSchaetz ( 2016-09-02 19:00:35 +0800 )edit

Is it possible tot create a fiddle that combines 2 MC with that problemen? I see if I van check it out

chillworld ( 2016-09-02 19:14:21 +0800 )edit

Thanks, will try. @ComponentAnnotation("@bind(vmsgs[self.id])") works quite fine. Problem now: My label+textbox+error mc could be used alone (then the BindContext.component.id would be the correct key for that) or inside another mc (then SavePropertyBinding.fieldName would be the correct key).

FlorianSchaetz ( 2016-09-02 19:36:52 +0800 )edit

answered 2016-09-02 15:49:45 +0800

maxspuls gravatar image maxspuls
1 2

Hi, in your component class you must put the following annotation

@ComponentAnnotation("error:@ZKBIND(ACCESS=both,SAVE_EVENT=on[Your Event])") public class [YourClass] extends ..... implements IdSpace{



public class OasiLabel extends Label implements IdSpace{

public void setBindValue(String value) {
    Events.sendEvent("onSetLabel", this, null);


link publish delete flag offensive edit


I am sorry, but while this is true, it has nothing to do with the question. This annotation allows me to bind fields to it, yes, true. But that already works. What I want to remove is the need to explicitly bind the validation message to it. I want it to be done automatically.

FlorianSchaetz ( 2016-09-02 16:03:51 +0800 )edit

ok I did not understand the problem :-)

maxspuls ( 2016-09-02 16:18:40 +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: 2016-09-02 09:12:40 +0800

Seen: 27 times

Last updated: Sep 02 '16

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