Jin Kwon
Jin Kwon

Reputation: 22017

How can I use Java's constants value as th:value name?

I have a constant for a name.

public static final NAME_SOME = "some"

In my html I tried,

<input th:value="${T(the.package.TheClass).NAME_SOME}"/>

I expected the actual value from the model named by some. Yet I see value=some.

How can I fix this?

Upvotes: 0

Views: 961

Answers (1)

Metroids
Metroids

Reputation: 20487

It's a bit unclear what you're asking. The expression <input th:value="${T(the.package.TheClass).NAME_SOME}" /> should indeed evaluate to <input value="some" />. You mean you have a form with a model object and you want to bind it to the expression model.some? You can use preprocessing to do that, I think...

<input th:field="*{__${T(the.package.TheClass).NAME_SOME}__}" />

Upvotes: 3

Related Questions