0

I'm trying to build an international application that can change locale dynamically on the page. I'm also trying to build a dynamic menu with labels and values that will change when the locale changes dynamically. This is what I tried:

    menuModel = new DynamicMenuModel();

    DefaultSubMenu inOfficeMailbox = new DefaultSubMenu("#{msg['inofficemailbox']}");

    DefaultMenuItem activeItem = new DefaultMenuItem( "#{msg['activeissues']}");
    activeItem.setCommand("#{mainMenuMB.loadContent('activeissues')}");
    inOfficeMailbox.addElement(activeItem);

    DefaultMenuItem resolvedItem = new DefaultMenuItem("#{msg['resolvedissues']}");
    resolvedItem.setCommand("#{mainMenuMB.loadContent('resolvedissues')}");
    inOfficeMailbox.addElement(resolvedItem);       

    menuModel.addElement(inOfficeMailbox);

but the menu item just come out with the literals "#{msg['blahblah']}". Where msg is the localization variable. Obviously the EL is not evaluated so the localization doesn't work. What should I do instead?

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • Do you have appropriate resource bundles? You can obtain them using `FacesContext context = FacesContext.getCurrentInstance();` `ResourceBundle resourceBundle = context.getApplication().evaluateExpressionGet(context, "#{messages}", ResourceBundle.class);` (where `#{messages}` is a `var` in `faces-config.xml` enclosed within a `` element) and then format using `MessageFormat#format(String pattern, Object... arguments);`. – Tiny Jul 23 '15 at 19:40
  • possible duplicate of [How can I get a message bundle string from inside a managed bean?](http://stackoverflow.com/questions/6272945/how-can-i-get-a-message-bundle-string-from-inside-a-managed-bean) – dognose Jul 23 '15 at 23:18
  • Yes I did, but that would require me to regenerate the entire menuModel every time someone changes the language. It is pretty messy in my opinion. Just wondering if there are more elegant ways to go about it. – Chieh-Li Jelly Lee Jul 28 '15 at 00:14

0 Answers0