Martin Erlic
Martin Erlic

Reputation: 5665

How can I send an enum value in a form in Spring Boot?

I want to pass an enum value as defined in the following class over a form:

package com.test.entity.common;

public enum RequestStatus {
    PENDING,
    APPROVED,
    REJECTED
}

The form:

<select th:field="*{selectedRequestType}">
   <option value="${T(com.test.entity.common.RequestStatus).PENDING}">PENDING</option>
   <option value="${T(com.test.entity.common.RequestStatus).APPROVED}">APPROVED</option>
   <option value="${T(com.test.entity.common.RequestStatus).REJECTED}">REJECTED</option>
</select>

Why does this return the entire value as the string literal T(com.test.entity.common.RequestStatus).REJECTED instead of just the enum REJECTED? Is there a way to do this using SpEL?

Upvotes: 3

Views: 1563

Answers (1)

Mavlarn
Mavlarn

Reputation: 3883

Just

<option value="PENDING">PENDING</option>

Will be fine. For enum type Spring Boot can convert the string to related enum automatically.

Upvotes: 4

Related Questions