I'm trying to get an Action in Struts 2 to work with an Enum as an input parameter. What I've done so far looks like:
public TestAction {
public enum Module {
VALUE1;
}
private Module module;
public void setModule(Module module) {
this.module = module;
}
public Module getModule() {
return module;
}
}
But when trying to use this I get an xwork conversion error, and the action itself doesn't even execute. Can I make this work as is, or should I provide setModule(String) myself?
Edit: I'm using struts 2.1.6 The URL I'm trying: /test.action?module=value1
It should bind a string to a enum straight away. I think the enum type converter has been in the default configuration since I think 2.1.x.
if you are unsure the following is in my xwork-conversion.properties
in a 2.0.14 app
java.lang.Enum = com.opensymphony.xwork2.util.EnumTypeConverter
EDIT: In response to the comment, if you need to ignore case for assigning an enum you have the following choices:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With