[jboss-user] [JBoss Seam] - Re: howto display the an enum object internationalized

knaas do-not-reply at jboss.com
Mon Aug 6 10:19:04 EDT 2007


What we did was to create an EnumConverter that uses the resource bundle for internationalization.  We just defined a convention "packagename.classname.enumvalue=Some text".
If we find something in the resource bundle, use it, otherwise just use the toString value of the enum.  

Something like this code.


  | 
  | @Override
  |     public String getAsString(final FacesContext context, final UIComponent component, final Object object) throws ConverterException
  |     {
  |         String retVal = null;
  |         if (object instanceof Enum)
  |         {
  |             Enum instance = (Enum)object;
  |             final String resourceKey = instance.getClass().getName() + "." + instance.name();
  |             try
  |             {
  |                 retVal = ResourceBundle.instance().getString(resourceKey);
  |             }
  |             catch (MissingResourceException e)
  |             {
  |                 //Ignore
  |             }
  |             if (StringUtils.isEmpty(retVal))
  |             {
  |                 retVal = instance.name();
  |             }
  |         }
  |         return retVal;
  |     }
  | 
  | 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4071203#4071203

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4071203



More information about the jboss-user mailing list