Example:
batchTag is an enumerated type attribute of a batchRange, with values like so:
JAN1 "January Biweekly 1",
JAN2 "January Biweekly 2",
etc.
I want to display the VALUE of the batchTag in the select, IOW, the select should contain
"January Biweekly 1"
"January Biweekly 2" ...
not
JAN1
JAN2
FEB1
FEB2
FEB3 ...
I have tried several things in the g:select to do this, but without any success. I thought perhaps "it" would be available as part of the g:select (as it is clearly an iteration) and tried to reference it.batchTag.name for the optionValue, but that did not work. Any suggestions?
Thank you!
An enum can, just like a class , have attributes and methods. The only difference is that enum constants are public , static and final (unchangeable - cannot be overridden).
An enum is a data type that can be created by a Java programmer to represent a small collection of possible values. Technically, an enum is a class and its possible values are objects.
ENUM values are sorted based on their index numbers, which depend on the order in which the enumeration members were listed in the column specification. For example, 'b' sorts before 'a' for ENUM('b', 'a') . The empty string sorts before nonempty strings, and NULL values sort before all other enumeration values.
Yes you can programmatically index an enum, text, or menu ring.
enum BatchRange {
JAN1 "January Biweekly 1",
JAN2 "January Biweekly 2",
final String value
BatchRange(String value) { this.value = value }
String toString() { value }
String getKey() { name() }
}
Note the getKey() method. And then your g:select
<g:select name="batch" from="${BatchRange.values()}" optionKey="key" />
or
<g:select name="batch" from="${BatchRange.values()}" keys="${BatchRange.values()*.name()}" />
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