Recuperar mensagem de messageBundle.properties

2 views
Skip to first unread message

marqu...@gmail.com

unread,
Nov 23, 2009, 8:09:38 PM11/23/09
to javasf: JavaServer Faces Group
Colegas,

Preciso recuperar uma mensagem do arquiivo messageBundle.properties em
uma classe.

Exemplo: No messageBundle.properties eu tenho:
key=descrição

Como eu recupero essa mensagem dada a key. Algo do tipo:

String msg = algumaFormaDeRecuperarMensagem(key);

Tem como?

Muito obrigado,

Marques




Diénert Vieira

unread,
Nov 23, 2009, 8:46:58 PM11/23/09
to jav...@googlegroups.com
Faça algo do tipo:

        public static String getResourceString(String key) {
                FacesContext context = FacesContext.getCurrentInstance();
                Locale locale = context.getViewRoot().getLocale();
                try {
                        ResourceBundle bundle = ResourceBundle.getBundle(context
                                        .getApplication().getMessageBundle(), locale);
                        return bundle.getString(key);
                } catch (MissingResourceException e) {
                        return key;
                }
        }


--
Diénert de Alencar Vieira
Sun Certified Java Programmer - SCJP 6
Graduado em Sistemas para Internet - IFPB
Bacharelando em Ciência da Computação - UFPB


Reply all
Reply to author
Forward
0 new messages