Access Resource Bundle in XPages from JAVA


import static com.ibm.xsp.extlib.util.ExtLibUtil.*;

public Object getGlobalObject(String obj) throws Exception {
   return resolveVariable(FacesContext.getCurrentInstance(),obj);
}

public String getLangString(String bundle,String key) throws Exception {
  try{
     ResourceBundle rb = (ResourceBundle)this.getGlobalObject(bundle);
     return rb.getString(key);
  }catch (Exception e) {
     e.printStackTrace();
     return "##NOT FOUND##";
  }
}

You now can use the method to return a value for a given key from a specific resoure bundle

getLangString('myButtonLabels','CANCEL');


All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.
1 comment(s)Login first to comment...
Clay Martin
(at 02:51 on 19.03.2015)
Just what I needed!

I am using an xAgent to generate a pdf and it wasn't working until I re-read your post "assume *.properties is included as a language resource in your XPage".