简体   繁体   中英

How do I add a message from a messages.properties to a catch?

We encounter some problems with the codification of some "special" characters like "ã" at work and so we are changing all the code to get the message in Unicode format from a message.properties file like this:

<h:outputLabel value="#{messages['guia.editar.numeroGuia']}" />

in the message properties it contains:

guia.editar.numeroGuia=N\u00FAmero da Guia\ 

Now these are working perfectly fine, however we need to replace all the catch messages to follow the same pattern. I need to import the message somehow to the catch block. Can anyone help me with it?

This method for example:

public List<GuiaAdm> getTodosRegistros() {
        try {
            return guiaAdmService.findNoPage(getParametrosPesquisa());
        } catch (ServiceException e) {
            this.messageFacesBean.reportarErro("Não foi possível gerar exportação devido a erro interno na pesquisa.");
        }
        return null;

    }

It should return the message: "Não foi possível gerar exportação devido a erro interno na pesquisa." however it returns: "Não foi possÃ-vel gerar exportação devido a erro interno na pesquisa." or something with even stranger characters and that's why we created the file to storage the messages in unicode format. Now we need to import this message to the catch, can anyone help me?

We already tried changing to unicode or ISO9688 and a few others but the problems didn't disappear.

After digging a little bit i found a topic related to this which brings a good solution. The link is: Use message bundle in Java class with Seam

The solution to my case would be:

this.messageFacesBean.reportarErro(Messages.instance().get("message.name"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM