0

@Command with parameters

asked 2011-12-19 10:26:07 +0800

ctapobep gravatar image ctapobep
163 2

Is it possible to pass the parameters to the command method? Can't find a way, blogs are silent about this.

delete flag offensive retag edit

18 Replies

Sort by ยป oldest newest

answered 2011-12-19 12:20:08 +0800

Matze2 gravatar image Matze2
773 7

The annotations @Param and @Default are supposed to be used together with @Command if you look in javadoc.
But I didn't do any investigations in that direction until now.

link publish delete flag offensive edit

answered 2011-12-19 13:29:41 +0800

ctapobep gravatar image ctapobep
163 2

updated 2011-12-19 13:32:20 +0800

Yeah, but the question is how to push parameters from ZUL.. Though I can't mark a method with @Param annotation, it shows an error.

link publish delete flag offensive edit

answered 2011-12-19 15:48:42 +0800

Matze2 gravatar image Matze2
773 7

Again just looking into zkbind.jar code, it seems you can put any named attribute in the ZUL command annotation, e.g.

<button label="Click" onClick="@command('click' arg1='value1')"/>

@Param is a PARAM annotation, so you need to place it near method parameter. The command method signature should look like the following:

@Command
public void click(@Param("arg1") String arg1)

This is for the syntax. I didn't try it though.

I am curious: what do you want to achieve?

link publish delete flag offensive edit

answered 2011-12-19 20:13:40 +0800

ctapobep gravatar image ctapobep
163 2

updated 2011-12-19 20:14:38 +0800

@Param is a PARAM annotation
Yeah, didn't notice hehe, it was obvious)
But the ZUL sample didn't help, it simply doesn't show any error in the log, but in the same time doesn't go into the method as well.
I have several identical buttons at different rows, and want to identify the command by specifying id of the row this button is placed at so that I can figure out on what row this action should be performed.
PS: where do you read that docs? I mean regarding ZUL markup.

link publish delete flag offensive edit

answered 2011-12-20 00:31:04 +0800

Matze2 gravatar image Matze2
773 7

I inspected the source code in zkbind.jar.

link publish delete flag offensive edit

answered 2011-12-20 09:50:14 +0800

Matze2 gravatar image Matze2
773 7

I found the following related blog entry.
The interesting part:


For a command method, add the @Command annotation. With this annotation, binder can provide more features, such as @Param and @Default for acquiring argument of the context as the method parameter. We will talk about these in upcoming small talks.

link publish delete flag offensive edit

answered 2011-12-20 11:40:23 +0800

ctapobep gravatar image ctapobep
163 2

I dunno why I didn't try this before, but this works:

onClick="@command('showGroupsDialog', label='aa', arg1='bb')
Uh.. spent so much time surfing the sources (which are really nasty) to figure our such a trivial thing.
Matze2, thanks for you help!

link publish delete flag offensive edit

answered 2011-12-20 12:37:58 +0800

ctapobep gravatar image ctapobep
163 2

Hm.. looks like you can't resolve ${} placeholders inside the @command:

      <button label="Add Group" sclass="add-group-button"
              onClick="@command('showGroupsDialog', mode='${arg.mode}')" />
I get a string "${arg.mode}" as a parameter, not the value of the expression..

link publish delete flag offensive edit

answered 2011-12-20 12:53:31 +0800

Matze2 gravatar image Matze2
773 7

Can you a give a small example how the counterpart - the @Command method - in the ViewModel looks like?

link publish delete flag offensive edit

answered 2011-12-20 13:09:18 +0800

ctapobep gravatar image ctapobep
163 2

    @Command()
    public void showGroupsDialog(@Param("mode") String mode) {}

link publish delete flag offensive edit
Your reply
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

RSS

Stats

Asked: 2011-12-19 10:26:07 +0800

Seen: 2,210 times

Last updated: Jul 27 '12

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