0

Enum as @command argument?

asked 2019-11-29 15:36:29 +0800

tisaksen gravatar image tisaksen
46 6

updated 2019-11-29 15:37:54 +0800

How can I pass an enum type as an argument to a command in a zul file?

<textbox onok="@command('myCommand', tag=MyEnum.MyConstant)"/>

@Command public void myCommand(@BindingParam("tag") MyEnum tag) { .... }

delete flag offensive retag edit

2 Answers

Sort by » oldest newest most voted
0

answered 2019-12-02 18:27:26 +0800

MDuchemin gravatar image MDuchemin
1501 1 5
ZK Team

Hi tisaksen,

You can, but you need to import your enum in zul first

<?import foo.bar.MyEnum?>
<zk>
...
<textbox...
link publish delete flag offensive edit

Comments

Thanks, however, I could not get it to work because Enum cannot be instantiated using reflection.

tisaksen ( 2019-12-03 17:56:26 +0800 )edit
0

answered 2019-12-03 18:52:17 +0800

MDuchemin gravatar image MDuchemin
1501 1 5
ZK Team

updated 2019-12-03 19:48:19 +0800

Hi tisaksen,

This is working on my side: zul:

    <?import foo.bar.MyEnum?>`
    <zk>
        <div viewModel="@id('vm')@init('foo.bar.EnumVm')">
            <button onClick="@command('myCommand', tag=MyEnum.MONDAY)" />
        </div>
    </zk>

EnunVm.java: public class EnumVm {

    @Command("myCommand")
    public void myCommand(@BindingParam("tag") MyEnum tag) {
        System.out.println(tag);
    }

}

If the <?import ?> processing instruction doesn't work, you can also import from zscript, or from a global import http://zkfiddle.org/sample/8p1lrf/1-mvvm-and-enum#source-1

You mentioned Enum cannot be instantiated using reflection, could you post a stacktrace or a code sample where you run in that limitation?

link publish delete flag offensive edit

Comments

It turned out to what seems to have been a problem my POM - I refactored it and the code is working. Thank you for your help :-)

tisaksen ( 2019-12-03 19:47:02 +0800 )edit

Good to hear :)

MDuchemin ( 2019-12-03 19:49:04 +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

Follow
2 followers

RSS

Stats

Asked: 2019-11-29 15:36:29 +0800

Seen: 21 times

Last updated: Dec 03

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