0

Is there a way to access the "Validation Message Holder" from within a view model?

asked 2013-12-05 12:42:41 +0800

georgefountopoulos gravatar image georgefountopoulos
0 1

updated 2013-12-06 12:48:56 +0800

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)
    }
}
delete flag offensive retag edit

Comments

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 )edit

I 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

2 Answers

Sort by » oldest newest most voted
1

answered 2013-12-06 03:53:46 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2619 3 8
http://emrpms.blogspot.in...

Check here

link publish delete flag offensive edit

Comments

1

Thanks Senthilchettyin

sjoshi ( 2013-12-06 04:53:07 +0800 )edit
1

answered 2013-12-06 07:20:07 +0800

cor3000 gravatar image cor3000
4596 2 7
ZK Team

updated 2013-12-06 07:20:18 +0800

Here an example that conforms to your initial request just passing the ViewModel to the init method, via @BindingParam.

Robert

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
1 follower

RSS

Stats

Asked: 2013-12-05 12:42:41 +0800

Seen: 56 times

Last updated: Dec 06 '13

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