Hello everyone,

I have a simple feature request. Can we get a method added to the AbstractViewController class that gets a message out of the applications configured message bundle? Something as simple as:

   protected String getMessage (String messageKey) {
ResourceBundle rb = ResourceBundle.getBundle (getApplication ().getMessageBundle (), getFacesContext ().getViewRoot ().getLocale ());
       return rb.getString (messageKey);
   }

Something that might also be useful is one that takes an optional Object[] as parameters and then uses MessageFormat to format the message:

   protected String getMessage (String messageKey, Object[] params) {
       String messageBundleName = getApplication ().getMessageBundle ();
       Locale locale = getFacesContext ().getViewRoot ().getLocale ();
ResourceBundle rb = ResourceBundle.getBundle (messageBundleName, locale);
       String msgPattern = rb.getString (messageKey);
       String message;
       if (params != null) {
           message = MessageFormat.format (msgPattern, params);
       } else {
           message = msgPattern;
       }
       return message;
   }


I've found this to be of tremendous help in simplifying error handling code, or when I want to display a success message or something like that. It makes things so much cleaner.


What do you think?

Thanks,
Rich

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to