|
The View tag is the container for all JavaServer Faces component tags used on a page. You can wrap the root element of the structured markup language used in your document with this tag to ensure that all child tags are part of the same view.
This tag is useful for internationalization (I18N) purposes. It provides you with several options for presenting your user with localized views of your application. By default the JSF framework will attempt to select the best view for your user based on the Accept-Language header sent to the server from the user's browser as part of the HTTP request for your page.
If the locale requested by the user is not supported by your application, the JSF framework will use the default locale specified in your Faces configuration file. If you have not specified a default locale, JSF will use the default locale for the Java Virtual Machine serving your application.
If your application supports the locale requested by the user, JSF will set that locale for the view and will display the messages for that locale defined in the locale's message bundle.
You can also specify the locale for which the view is to be rendered by explicitly setting the locale attribute of the view tag. This allows you to design localized versions of each page, including images and styles, for each locale you wish to support.
Another option is to obtain the locale dynamically through user interaction. This information could later be stored in a cookie and/or a database to identify which locale is preferred by your user. The locale attribute accepts a value-binding expression that could resolve to the desired locale.
Example:
welcome_en.jsp (English)
<f:view locale="en">
<f:loadBundle basename="com.mycompany.MessageBundle" var="bundle" />
<h:outputText value="#{bundle.welcomeMessage}" />
</f:view>
welcome_fr.jsp (French)
<f:view locale="fr">
<f:loadBundle basename="com.mycompany.MessageBundle" var="bundle" />
<h:outputText value="#{bundle.welcomeMessage}" />
</f:view>
HTML Output
welcome_en.jsp (English)
Welcome to our site!
welcome_fr.jsp (French)
Bienvenue à notre site!
|