如何在JSF中创建新的消息属性文件以添加适当的错误消息 [英] How to create new messages properties file in JSF to add adeqate error messages

查看:101
本文介绍了如何在JSF中创建新的消息属性文件以添加适当的错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是JSF的新手.我不了解如何创建自己的消息属性文件以及该文件的确切位置.有人可以帮我吗?

I am new to JSF. I do not understand how to create my own messages properties files and where exactly to put this file. Can anyone help me with this?

推荐答案

我没有得到如何创建自己的属性文件的方法

I am not getting how to create new my own properties file

根据 java.util.Properties 合同.具有key=value对的ISO-8859-1编码文本,每个文本在其自己的行中.如果是JSF消息资源,则可以使用JSF规范中描述的键名来覆盖默认消息.您可以在JSF规范的第2.5.2.4章中找到它们(此处是 JSF 1.2规范 JSF 2.0规范).

Create a text file according the java.util.Properties contract. ISO-8859-1 encoded text with key=value pairs, each in its own line. In case of JSF message resource, you can use the key names as described in the JSF specification to override default messages. You can find them in chapter 2.5.2.4 of the JSF specification (here are the JSF 1.2 specification and JSF 2.0 specification).

以及将此文件放在目录下的位置

and where to put this file under directory

只需将其放入类路径中即可,就像处理普通的Java类一样.

Just put it in the classpath as you do with your normal Java classes.

faces-config.xml文件中的<message-bundle>应该引用资源的完整限定路径名.如果您已将属性文件命名为Messages.properties并刚刚放在类路径的根目录中,则其声明应类似于

The <message-bundle> in faces-config.xml file should refer to the full qualified pathname of the resource. If you've named the properties file Messages.properties and just dropped in the root of the classpath, then its declaration should look like

<application>
    <message-bundle>Messages</message-bundle>
</application>

但是,如果您将其放入包com.example.i18n中,则其外观应为:

But if you've dropped it in for example the package com.example.i18n, then it should look like:

<application>
    <message-bundle>com.example.i18n.Messages</message-bundle>
</application>

这篇关于如何在JSF中创建新的消息属性文件以添加适当的错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆