-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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) { .... }
Hi tisaksen,
You can, but you need to import your enum in zul first
<?import foo.bar.MyEnum?>
<zk>
...
<textbox...
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?
Asked: 2019-11-29 15:36:29 +0800
Seen: 23 times
Last updated: Dec 03 '19