1 package org.apache.myfaces.examples.util; 2 3 import javax.faces.context.FacesContext; 4 import java.util.ResourceBundle ; 5 import java.util.MissingResourceException ; 6 import java.text.MessageFormat ; 7 8 12 public class GuiUtil 13 { 14 private static String BUNDLE_NAME = "org.apache.myfaces.examples.resource.example_messages"; 15 16 public static String getMessageResource(String key, Object [] arguments) 17 { 18 FacesContext context = FacesContext.getCurrentInstance(); 19 String resourceString; 20 try 21 { 22 ResourceBundle bundle = ResourceBundle.getBundle(BUNDLE_NAME, context.getViewRoot().getLocale()); 23 resourceString = bundle.getString(key); 24 } 25 catch (MissingResourceException e) 26 { 27 return key; 28 } 29 30 if (arguments == null) return resourceString; 31 32 MessageFormat format = new MessageFormat (resourceString, context.getViewRoot().getLocale()); 33 return format.format(arguments); 34 } 35 36 } 37 | Popular Tags |