Use of facelets in JSF and JSF internationalization issues

Source: Internet
Author: User
Tags locale

Facelet Introduction: Facelet is for the JSF component model tailor-made template language, the white page is the template, we can first of all the frame of the page to build up the dynamic part we can directly to reference. This will reduce the number of duplicate code written. While this means that the facelet itself has a high degree of integration with the JSF lifecycle, using Facelets, the resulting template builds the component tree, not the servlet. This allows for better reuse because components can be combined into another component.

II Facelet Usage: First, the insertion of tag library

Template page: On the template page, we use the <ui:insert/> tag, we can directly use <ui:include/> reference page in the label, also can be vacant. Take a look at the following example:

     <f:view locale= "ZH_CN" > <f:loadbundle basename= "Messages" var= "msgs"/> Dynamic page: When the template page is generated, we can dynamically generate each page. First we need to use the <ui:composition template= "template.xhtml"/> tag to introduce the template page above. The content of the page is then dynamically defined with the <ui:define/> tag. Examples are as follows:

Page styles and scripts: the introduction of styles and scripts is typically placed inside the 

Iii. the question of JSF internationalization

You must first define a national configuration file with a name format of xxx_language.properties, such as Message_en.properties,message_zh_ Cn.properties, then we need to introduce on the template page, you can refer to the top of the template.xhtml page

<f:loadbundle basename= "Messages" var= "Msgs"/>
When we need to initialize local locals, we simply add the following phrase
<f:view locale= "ZH_CN" >
In specific use, only need to call the definition of the language on it, the following gives a complete example

And the internationalization of the file definition is very simple, such as the first is an en language

Login.logo = Login
login.username = User Name
login.userpasswd = Password
Login.userpermiss = Permission
login.administrator = Administrator
login.operator = operator
login.viewer = Viewer
Login.submit = Submit
login.cancel = Cancel
Then it's ZH_CN language.

Login.logo = Login
login.username = user
login.userpasswd = password
login.userpermiss = permission
login.administrator = Administrator
login.operator = operator
login.viewer = Monitor
login.submit = OK
login.cancel = Cancel

This is a bit of experience with JSF.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.