JSF view Tag

This tag is used to create the top level view. This acts as a container of all the components that are part of the view of the page.

JSF view Tag

JSF view Tag

        

This tag is used to create the top level view. This acts as a container of all the components that are part of the view of the page. Its attribute "locale" is important in the case of making the view internationalized. We can do so by setting the locale attribute to the locale you have to present the view of the page. Suppose we set the locale attribute to "en" or "fr" then the view is presented to the user in English and French respectively. you can also set the locale dynamically and can present the view according to the user.

Code Description :

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>

<f:view locale="fr">
 <html>
  <head>
  <link href="corestyle.css" rel="stylesheet" type="text/css"/>
  </head>
  <body>
   <h:form> 
  <h:inputText id="ab" value="#{MessageBean.b}" required="true"/>
  <h:message for="ab" errorClass="errors"/><br>
  <h:commandButton value="go"/>
   </h:form>
  </body>
 </html>
</f:view>

Rendered Output : In the above code all component tags have been embedded in the view tag.

In the above tag we have set the locale attribute to "fr" i.e. French locale. In the above code we have used message tag to display the error message if the input field is left blank. So this message is shown in French because of the locale set in the code. The output is shown below.

Html Source Code :

<html>
   <head>
   <link href="corestyle.css" rel="stylesheet" type="text/css"/>
   </head>
   <body>
  <form id="_id0" method="post" action="/coretag/pages/view.jsf"   enctype="application/x-www-form-urlencoded">
   <input id="_id0:ab" type="text" name="_id0:ab" value="" /><br>
   <input type="submit" name="_id0:_id2" value="go" />
   <input type="hidden" name="_id0" value="_id0" /></form>
   </body>
</html>

Attributes that this tag uses are given below :

locale : This attribute is used to set the locale of the view. Its default value is that specified in configuration file. It can take static values or EL expressions.