JSF 2 h outputLabel

JSF 2 h outputLabel


Posted in : Java Posted on : August 1, 2012 at 10:41 AM Comments : [ 0 ]

In this tutorial you will learn about the JSF 2 h outputLabel tag.

JSF 2 h outputLabel

In this tutorial you will learn about the JSF 2 h outputLabel tag.

<h:outputLabel> tag of JSF 2 html tag library is rendered the HTML label element. This tag is used to specify the label text of the current component value. The for attribute of this tag (if used) specifies the target component is to be labeled. The value of 'for' attribute renders the targeted component's id value.

Attributes of JSF 2 h outputLabel

  • converter : This is an optional attribute. This attribute is used when you are required to use any Converter class with this compoent.
  • id : This is an optional attribute. This attribute is used to make the component uniquely identifiable. The value of this attribute must be unique within the closest parent component.
  • rendered : This is an optional attribute. This attribute evaluates a boolean expression. Presence of this attribute specifies that whether the current component should be rendered in the Rendered Response phase or not or worked on any later form submission. The default value of this attribute is defined to true.
  • value : This is an optional attribute. This attribute specifies the current value of the component.
  • accesskey : This is an optional attribute. This attribute evaluates the java.lang.String value, acted as an access key i.e used to create a keyboard shortcut which can be accessed by the combination of Alt+accesskeyValue or Alt+Shift+accesskeyValue (browser dependent combination) which transfers the focus to the current element when it is pressed.
  • dir : This is not a required attribute. This attribute evaluates to the java.lang.String value that suggests the direction for the text which doesn't inherit the property of maintaining a direction. The allowable values are "LTR (Left-to-Right)" and "RTL (Right-to-Left)".
  • escape : This is an optional attribute. This attribute is used to specify whether the HTML, XML instructions must be escaped or not. If this attribute is not used with this tag it is assumed that it's value is true and the HTML, XML characters must not be executed.
  • for : This is an optional attribute. This attribute specifies that which component has to be labeled. This attribute renders the target component's id's value.
  • lang : This is an optional attribute. This attribute specifies the language code for the component.
  • onblur : This is an optional attribute. This attribute evaluates to a java.lang.String which specifies that on the lossing of element's focus a Javascript code is executed.
  • onclick : This is an optional attribute. This attribute evaluates to a java.lang.String which specifies that on clicking of the mouse pointer button on the current element a Javascript code is executed.
  • ondblclick : This is an optional attribute. This attribute evaluates to a java.lang.String which specifies that on the double clicking of the current element by mouse pointer button a Javascript code will be executed.
  • onfocus : This is an optional attribute. This attribute evaluates to a java.lang.String which specifies that on geting focus of the current element a Javascript code will be executed.
  • onkeydown : This is an optional attribute. This attribute evaluates to a java.lang.String which specifies that on pressing down of the key over the current element a Javascript code is executed.
  • onkeypress : This is an optional attribute. This attribute evaluates to a java.lang.String value, specifies that when a key is pressed and released throughout the current element a JavaScript code is executed.
  • onkeyup : This is an optional attribute. This attribute evaluates to a java.lang.String value, specifies that on releasing of key over the current element a Javascript code is executed.
  • onmousedown : This is an optional attribute. This attribute evaluates to a java.lang.String value, specifies that on pressing down of the mouse pointer button over the current element a Javascript code is executed.
  • onmousemove : This is an optional attribute. This attribute evaluates to a java.lang.String value, specifies that on moving of the mouse pointer button inside the current element a Javascript code is executed.
  • onmouseout : This is an optional attribute. This attribute evaluates to a java.lang.String value, specifies that on moving away of the mouse pointer button from the current element a Javascript code is executed.
  • onmouseover : This is an optional attribute. This attribute evaluates to a java.lang.String value, specifies that on moving of the mouse pointer button onto the current element a Javascript code is executed.
  • onmouseup : This is an optional attribute. This attribute evaluates to a java.lang.String value, specifies that on releasing of mouse pointer button above from the current element a Javascript code is executed.
  • style : This is an optional attribute. This attribute evaluates to a java.lang.String value, which specifies that the CSS style will be applied to this component when rendered.
  • styleClass : This is an optional attribute. This attribute evaluates to a java.lang.String value specifies the applicable CSS style space-separated list to applied at the time of rendering. "class" attribute must be used to pass this value.
  • tabindex : This is an optional attribute. This attribute evaluates to a java.lang.String value specifies the tabbing order value. This value must be an integer within the range 0 to 32767.
  • title : This is an optional attribute. This attribute is used to specify the title information which will be displayed as tooltip about the markup elements.
  • binding : This is an optional attribute. This attribute evaluates to a javax.faces.component.UIComponent specified for linking the component with the property of backing bean.

Example :

Here is a simple example given for you which demonstrate about the use of JSF 2 h outputLabel tag. In this example a JSF view page has been created where the <h:outputLabel> tag is used.

Directory Structure

NameBean.java

package devmanuals;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

@ManagedBean(name="nameBean")
@RequestScoped
public class NameBean {

String name;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}

jsfHtmlOutputLabel.xhtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">

<h:head>
<title>JSF 2 h outputLabel Example</title>
</h:head>
<h:body>
<f:view>
<h:form>
<h:outputLabel value="Name " for="text1"/>
<h:inputText id="text1" value="#{nameBean.name}"/>
<h:commandButton value="submit" action="output"/>
</h:form>
</f:view>
</h:body>
</html>

output.xhtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">

<h:head>
<title>JSF 2 h outptuLabel Example</title>
</h:head>
<h:body>
<h:outputLabel value="Name : " for="out1" />
<h:outputText id="out1" value="#{nameBean.name}"/>
</h:body>
</html>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>jsfHOutputLabel</display-name>
<welcome-file-list>
<welcome-file>jsfHtmlOutputLabel.xhtml</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
<url-pattern>*.jsf</url-pattern>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
</web-app>

How To Run

After copying the above code paste them to the respective files or by downloading the code from Download Source Code start your web server and then use the following link http://localhost:8181/jsfHOutputLabel/jsfHtmlOutputLabel.xhtml in the address bar of the web browser.

Output :

When you will execute the above example you will get the output as follows :

1. The main page will look like as follows :

2. When you will enter the value to the provided text box and clicked on submit button then the output will be as follows :

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics