allwiki首页  
天下维客 你可以修改的网络知识库
首页最近更改优秀条目专题展示电脑科技词典软件学习网络知识电脑安全明星时尚天下百科
 

JSF Quickstart With MyEclipse---5

天下维客,你可以修改的网络知识库

Jump to: navigation, search

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.

Image:jsf-create-message-bundle.gif

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.

Image:jsf-create-message-file-annot.gif

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.

Personal tools
工具
金银币拍卖 金币拍卖预展  金银币网店 熊猫金银币 生肖金银币