Jan
Jan

Reputation: 3401

Getting values from an enum and assign each in a checkbox in grails

Here is my enum class

enum TableStatus {
AVAILABLE("Available"), OCCUPIED("Occupied"), RESERVED("Reserved"), MERGED("Merged")

static final TableStatus DEFAULT = AVAILABLE

final String value

TableStatus(String value){
    this.value = value
}

public String toString(){
    value
}
   }

Here is my html snippet. I cant get the syntax right on the values

<label class="radio-inline" style="width:auto"> <input type="radio" name="status" value="${enums.TableStatus?.AVAILABLE*}">Available</label

<label class="radio-inline" style="width:auto"> <input type="radio" name="status" value="${enums.TableStatus?.OCCUPIED*}">Occupied</label> 

<label class="radio-inline" style="width:auto"> <input type="radio" name="status" value="${enums.TableStatus?.RESERVED*}">Reserved</label>

Upvotes: 1

Views: 1489

Answers (1)

Benoit Wickramarachi
Benoit Wickramarachi

Reputation: 6226

Input enum values as String such as AVAILABLE, OCCUPIED, etc...

To get back the Enum, convert the String value into an Enum in the controller using:

TableStatus statusEnum = TableStatus.valueOf("**StringValueHere**")

Note: to generate each radio box you can iterate on the TableStatus enum using a g:each tag:

<g:each var="status" in="${TableStatus.values()}">
...
</g:each>

Upvotes: 1

Related Questions