Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 756
JamieRhys Avatar asked Jan 01 '26 08:01

JamieRhys


1 Answers

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)}
like image 140
JamieRhys Avatar answered Jan 03 '26 12:01

JamieRhys



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!