Reputation: 5243
How can I get a properties file from CDI bean, I mean properties file for internationalization purposes as mentioned here.
In @ManagedBean
everything is simple @ManagedProperty(name="....")
but I can't encounter the way to achieve the same in CDI bean.
Thank you very much.
Upvotes: 0
Views: 448
Reputation: 11723
If you're looking for internationalization support within CDI for JSF purposes, you may want to look at DeltaSpike's JSF module. It builds off of the core i18n support available in core.
Upvotes: 1
Reputation: 20691
As far as I know, CDI doesn't support the kind of field-level access that @ManagedProperty
gives (where you can have @ManagedProperty(name="#{msgs.title}")
). If you want that level of control in CDI, you'll have to write a CDI Producer.
Considering that the resource bundle is simply a class of ResourceBundle
, you could easily obtain your defined bundle with:
FacesContext ctxt = FacesContext.getCurrentInstance();
ResourceBundle bundle = ctxt.getApplication().getResourceBundle(ctxt, aValue);
bundle.get("title");
Alternatively, you could simply inject either your FacesContext
or Application
into your bean:
@Inject
Application theApplication
public void getBundle{
ResourceBundle bundle = theApplication.getResourceBundle(ctxt, aValue);
}
Upvotes: 1