java - Injecting MessageSource into an Enum -
i trying use enum form:select such:
<form:select path="myenum"> <form:options itemlabel="resourcebundlelabel" /> </form:select>
with enum looks like:
public enum myenum { one("rb.one"), two("rb.two"); private messagesource messagesource; private string rbkey; public string getresourcebundlelabel() { httpservletrequest request = ((servletrequestattributes) requestcontextholder.getrequestattributes()).getrequest(); locale locale = request.getlocale(); return messagesource.getmessage(this.rbkey, null, locale); } public myenum(string rbkey) { this.rbkey = rbkey; } }
the problem can't seem figure out how messagesource injected. tried adding @component , @autowired (got error because there no default constructor. tried switching @component @configurable. tried removing both annotation, , implementing messagesourceaware. in cases, messagesource null when inside getresourcebundlelable().
ultimately, trying accomplish build out select options using enum, make such uses proper resource bundle , local. wasting time on not feasible?
see answer here how inject dependencies enums minimal plumbing.
Comments
Post a Comment