Using an enum within a nested class with Thymeleaf and Spring Boot

Issue

I have the following class:

Types.java:

public class Types {
    public static class PC {
        public static enum Motherboard {
            OPTION1("option 1"),
            OPTION2("option 2"),
            OPTION3("option 3");

            private final String displayValue;

            private Motherboard(String displayValue) { this.displayValue = displayValue; }

            public String getDisplayValue() { return this.displayValue; }
        }
    };
};

In my Thymeleaf template I have:

<select name="select-motherboard">
    <option th:each="size : ${T(jre.maintainme.utils.strings.Types.PC.Motherboard).values()}" th:value="${size}" th:text="${size.displayValue}"></option>
</select>

However, this doesn’t seem to work. If however, I put the Motherboard enum into the Types Class, it does… Is there a way I’m missing to be able to nest enums in classes and use them in Thymeleaf?

Solution

SOLUTION:

In order to go into nested classes, you need to add a $ between them. I.e:

${T(jre.maintainme.utils.strings.Types$PC$Motherboard)}

Answered By – JamieRhys

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published