-
FEATURED COMPONENTS
First time here? Check out the FAQ!
For example, I am trying to do something like this:
<div apply="grailsBindComposer"
viewModel="@id('vm') @init('testViewModel')"
validationMessages="@id('vmsgs')">
<label value="@load(vmsgs['key'])"/>
</div>
class TestViewModel {
@Init
void init() {
vmsgs.put("key", "value")
}
}
Looking at the documentation I could not find any example of how to access the ‘Validation Message Holder’ from within the view model.
Update: Thank you for your answers.
Here is how I implemented my requirement with ZKGrails 2.2.0 and ZK 6.5.2 EE:
<div apply="grailsBindComposer"
viewModel="@id('vm') @init('testViewModel')"
validationMessages="@id('vmsgs')">
<label value="@load(vmsgs['key'])”/>
</div>
class TestViewModel {
ValidationMessages vmsgs
@Init
void init(@ContextParam(ContextType.BINDER) Binder binder) {
vmsgs = ((BinderCtrl) binder).validationMessages
addInvalidMessage("key", "value")
}
void addInvalidMessage(String key, String message) {
addInvalidMessages(key, [message].toArray(new String[1]))
}
void addInvalidMessages(String key, String[] messages) {
vmsgs.addMessages(null, null, key, messages)
}
}
Check here
Here an example that conforms to your initial request just passing the ViewModel to the init method, via @BindingParam.
Robert
Asked: 2013-12-05 12:42:41 +0800
Seen: 56 times
Last updated: Dec 06 '13
Which ZK Version you are using If you are using Zk6 I will suggest a easy way to achieve this first let me know version
sjoshi ( 2013-12-05 13:12:20 +0800 )editI am using version 6.5.2, however I would like to know if it is possible in version 7 as well.
georgefountopoulos ( 2013-12-05 14:57:29 +0800 )edit