JSF Quickstart With MyEclipse---5
天下维客,你可以修改的网络知识库
|
JSF编辑 相关文档:
其他资源: |
Creating the Message Bundle
Before we can complete our development and specify deployment properties by creating with the faces-config.xml file, we must create the application's message bundle. As we saw in the JSP section of this tutorial, JSF provides mechanisms by which an application interface can be easily internationalized and localized through message bundles. As an analogy, Struts provided similar support in this area by way of the ApplicationResources.properties file, the various <bean /> tags, and the message bundle attributes that the bean tags accepted.
In JSF we can load a message bundle into a page with the line: <f:loadBundle basename="com.jsfdemo.MessageBundle" var= "bundle"/>
Note: The namespace of 'f' is arbitrary and was stipulated in the example code in Figure 8, line 3. Additionally, this line of code creates a page-scoped message bundle, that we can reference later in the page via the 'bundle' variable name, use to lookup messages keys and return the associated message value.
To create the message bundle file, we'll use the New File Wizard that is accessed from the context menu of the project by right-clicking on the project's 'source' folder and selecting New > File, as shown in Figure 13 below.
Figure 13 - Creating the Message Bundle file
When specifying the file location, select Browse..., choose the directory /JSFLoginDemo/src/com/jsfdemo, name the file MessageBundle.properties, and select Finish.
Figure 14 - Configuring the MessageBundle.properties File Using the Wizard
After successfully creating the new message bundle file, we need to fill the file with key/value pairs that match the message keys we used in the JSP pages from the previous sections. Please paste the contents from Figure 15 into your message bundle file and save it:
MessageBundle.properties user_name_label=User Name: user_password_label=Password: login_button_label=Login Figure 15 - Contents of MessageBundle.properties
This completes all of the code development for the example application. In the next section we'll configure the applications navigation by creating the faces-config.xml deployment descriptor.




