0

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).

BamaPookie
  • 2,560
  • 1
  • 16
  • 21
  • 2
    @SotiriosDelimanolis: nice try with that `` and then saying "You can use jstl". You deleted it on time before I got the chance to downvote that nonsense. – BalusC Aug 28 '13 at 17:39
  • I should add that 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. – BamaPookie Aug 28 '13 at 20:10
  • Also, if there is a better way to manage these key names in lieu of using constants as I have, I would love to hear it. – BamaPookie Aug 28 '13 at 20:13
  • It looks like the second part of my question is answered here: http://stackoverflow.com/questions/12401034/jsp-expressions-and-dynamic-attribute-names – BamaPookie Aug 29 '13 at 04:23

0 Answers0