Предположим, что у меня есть файл messages.properties, например
windowTitle=Accessing Form Elements with JavaScript
namePrompt=Name:
passwordPrompt=Password:
confirmPasswordPrompt=Confirm Password:
У меня есть запись для этого в моих лицах - config.xml, вроде этого
<faces-config version="2.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">
<application>
<resource-bundle>
<base-name>pk.mazars.basitMahmood.messages</base-name>
<var>msgs</var>
</resource-bundle>
</application>
</faces-config>
На моей странице xhtml я могу получить к ней доступ, как это
<h:panelGrid columns="2" columnClasses="evenColumns, oddColumns">
#{msgs.namePrompt}
<h:inputText/>
#{msgs.passwordPrompt}
<h:inputSecret id="password"/>
#{msgs.confirmPasswordPrompt}
<h:inputSecret id="passwordConfirm"/>
</h:panelGrid>
Но как я могу прочитать этот файл с Java. Например, предположим, что я должен напечатать такое сообщение, или запросить пользователя, как Имя должно быть введено
System.out.println(msgs.namePrompt + "must be entered")
Как я могу прочитать значение msgs.namePrompt из моего java-кода.
Также предположим, что у меня есть запись в моем файле сообщения, подобном этому
sure=Are you sure, you want to delete the <Field>?
remove=Are you sure you want to remove the<Field> and <Field>?
close=Are you sure you want to mark the <Field> as Closed?
created=<Field> is successfully created
updated=<Field> is successfully updated
Есть ли какой-либо метод, который я могу передать параметру в файл messages.properties. Как я хочу сделать что-то подобное в моем java-коде
System.out.println(msgs.sure("Name")); //<Field> is replace with Name
System.out.println(msgs.remove("Age", "Gender")); // First Field replace by Age, and second is replace by Gender
Спасибо.