Documentation
JSFToolbox

Search 

Contents

  1. Introduction
  2. Getting Started
  3. Developing Web Sites
  4. Using Components
  5. Internationalization
  6. Code View Support
  7. Design View Support
  8. Keyboard Shortcuts
  9. Tag Object Toolbars
  10. JSF Server Behaviors
  11. Property Inspectors
Selected 12. JSF Tag Reference

12. JSF Tag Reference

Contents > JSF Tag Reference > JSF Core Tags

10. JSF Core Tag Reference

Contents > JSF Core Tag Reference > f:view

f:view

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!

Tag Attributes

locale String
 
The locale attribute sets the locale to use for localizing this page. Literal values and value-binding expressions must evaluate to a java.util.Locale or to a String that can be converted to a Locale.