I have an Enum containing three different types of status. These statuses should be displayed in an email sent to users, and the lines containing the statuses that will be displayed are stored in messages.properties (read using the Spring class implementation org.springframework.context.MessageSource). This works well in a regular Spring controller. However, I would rather get the “display status” in Enum (to keep the logic in one place).
However, the automatic posting of the message source for listing, as in the following code, does not seem to work because the messageSource property is always empty.
public enum InitechStatus{
OPEN("open"), CLOSED("closed"), BROKEN("broken");
public final String name;
@Autowired
private MessageSource messageSource;
InitechStatus(String name) {
this.name = name;
}
@Override
public String toString() {
String displayStatusString = messageSource.getMessage("page.systemadministration.broadcastmail.status."
+ this.name, null, Locale.ENGLISH);
return displayStatusString;
}
}
Enum ( , )?