I have a Constants class with a bunch of static final strings as names for various keys like this:
class Constants {
public static final String MESSAGE_KEY = "messageKey";
}
They are to be used as model attribute names. In my controller class I have something like:
model.addAttribute(Constants.MESSAGE_KEY, "example.success");
and I want to access it something like this:
<c:if test="${!empty Constants.MESSAGE_KEY}">
<spring:message code="${Constants.MESSAGE_KEY}" />
</c:if>
Is there some way to do this, or am I way off base?
Edited to add:
I am trying to access the model attribute named messageKey in this case, not the text "messageKey". Currently, I have to hard code the key name as ${messageKey} or ${!empty messageKey} to access the value. I am trying to manage the string names of these model attributes with the Constant class, but I also need to access the attribute associated with that string name without hard coding the name (defeating the purpose of the name management in the first place).