How to obtain the equivalent applicationResourcesProvider["mykey"] in Java code

In my portlet I reference labels captions with #{activePreferencesBean.XYZApp.applicationResourcesProvider[“mylabelkey”]} witch resolve to the files AppResources_xx.properties I have in the project.

But I need do the same (to generate localized messages) in Java using this same application provider (and files)

I test with ContextUtils.localizeMessage(ContextUtils.getFacesContext(), “AppResources”, “prueba”, null, false) but It returns an exception “Unable to load ResourceBundle, basename=AppResources, locale=en”

How can I do it?

If your code is inside of a managed bean, then the simplest way would be to use the same expression and resolve it from the provided java API.

For example:

String msg = (String)resolveExpression("#{activePreferencesBean.XYZApp.applicationResourcesProvider['mylabelkey']}");
  1. http://techcommunity.softwareag.com/ecosystem/documentation/webmethods/wmsuites/wmsuite9-6/My_webMethods/9-6_CAF_and_MWS_Java_API_Reference/com/webmethods/caf/faces/bean/BaseFacesBean.html#resolveExpression(java.lang.String)

Thank you for your solution.

Another way I have found:

public String getLocalString(String key) {
  FacesContext context = ContextUtils.getFacesContext();
  ResourceBundle bundle = ResourceBundle.getBundle(context.getApplication().getMessageBundle(), ContextUtils.getResponseLocale(context));
  return bundle.getString(key); 
}

Or:

public String getLocalString(String key) {
  ResourceBundle bundle = ResourceBundle.getBundle(getFacesContext().getApplication().getMessageBundle());
  return bundle.getString(key);
}