简体   繁体   English

如何将消息从messages.properties添加到捕获?

[英]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: 我们在工作中编码某些特殊字符(例如“ã”)时遇到了一些问题,因此我们正在更改所有代码,以便从message.properties文件中以Unicode格式获取消息,如下所示:

<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. 现在,它们工作正常,但是我们需要替换所有catch消息以遵循相同的模式。 I need to import the message somehow to the catch block. 我需要将消息以某种方式导入到catch块。 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." 它应该返回以下消息:“Nãofoipossívelgerarexportaçãodevido a erro interno na pesquisa”。 however it returns: "Não foi possÃ-vel gerar exportação devido a erro interno na pesquisa." 但是它返回:“NÃoo foipossÃ-velgerarexportaçã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. 甚至带有陌生字符的东西,这就是为什么我们创建文件以unicode格式存储消息的原因。 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. 我们已经尝试过改用unicode或ISO9688以及其他一些,但是问题并没有消失。

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 链接是: 在Java类中将消息束与Seam一起使用

The solution to my case would be: 我的情况的解决方案是:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将&#39;main / src / ... / messages.properties&#39;文件添加到ShrinkWrap WebArchive? - How to add 'main/src/…/messages.properties' file to ShrinkWrap WebArchive? 如何在messages.properties文件中使用命名参数? - How can I used named parameters in a messages.properties file? 在Grails中,如何获取locale的ConfigObject of messages.properties? - In Grails, how can I get a ConfigObject of messages.properties for locale? "如何在 messages.properties 文件中使用参数?" - How can I use parameters in a messages.properties file? 如何在注释中读取messages.properties - how to read messages.properties in Annotations 清理messages.properties - clean messages.properties Grails从外部JavaScript文件中的messages.properties设置错误消息 - Grails Set Error Message From messages.properties In External JavaScript File 在spring message.properties中,如何在使用错误代码作为键时确保错误消息的换行符? - In a spring messages.properties, how to ensure line break of error message when using an error code as key? 如何使用messages.properties文件向SWT对话框添加键盘快捷键? - How to add keyboard shortcuts to SWT dialog using messages.properties file? 从messages.properties访问application.properties - Access application.properties from messages.properties
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM