JSF 2 h outputLink

JSF 2 h outputLink


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

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

JSF 2 h outputLink

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

<h:outputLink> tag of JSF 2 html tag library is rendered an HTML <a> (anchor) element. Body of this tag is rendered as the link text (anchor text). The 'value' attribute of this tag specifies the URL linked-to. This is as similar to the value what we were supplied to the HTML <a> 'href' attribute. So, with this tag the navigation rule can't be applied.

NOTE : If you will not use the value attribute the 'href' attribute in HTML code will assume the current page URL.

Attributes of JSF 2 h outputLink

  • converter : This is not a required attribute. This attribute is used when you are required to invoke a converter class in your application when this link is clicked.
     
  • id : This is not a required attribute. This attribute is used to make the element uniquely identifiable. Value of this attribute must be the unique within its closest parent component.
     
  • rendered : This is not a required attribute. It 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 not a required attribute. This attribute specifies the page link. Value of this attribute is rendered as the value of HTML 'href' attribute of <a> element.
     
  • accesskey : This is not a required 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.

  • charset : This is not a required attribute. This attribute is used to specify the character encoding of the resource.
  • coords : This is not a required attribute. This attribute is used to specify the position and shape for spotting the element on screen. Generally used at the client side image maps
  • 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)".
     
  • disabled : This is not a required attribute. This attribute evaluates to a boolean value which specifies whether this element will be get focused or be admitted  in the later form submission or not.
     
  • hreflang : This is not a required attribute. This attribute is used to specify the resource's language code assigned by this hyperlink.
  • lang : This is not a required attribute. This attribute is used to specify the language code for the component.
  • onblur : This is not a required attribute. This attribute evaluates to a java.lang.String value, specifies that when the focus of this element is getting lost a Javascript code is executed.
     
  • onclick : This is not a required attribute. This attribute evaluates to a java.lang.String value, specifies that on clicking of mouse pointer button over the current element a Javascript code will be executed.
     
  • ondblclick : This is not a required attribute. This attribute evaluates to a java.lang.String value, specifies that on the clicking of mouse pointer button double over the current element a Javascript code will be executed.
     
  • onfocus : This is not a required attribute. This attribute evaluates to a java.lang.String value, specifies that when a current link gets the focus a Javascript code will be executed.
     
  • onkeydown : This is not a required attribute. This attribute evaluates to a java.lang.String value, specifies that on a key pressed down throughout the current element a JavaScript code is executed.
     
  • onkeypress : This is not a required 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 not a required attribute. This attribute evaluates to a java.lang.String value. Code of Javascript is executed on releasing of the key over the current element.
     
  • onmousedown : This is not a required attribute. This attribute evaluates to a java.lang.String value. Code of Javascript is run on pressing down the mouse pointer.
  • onmousemove : This is not a required attribute. This attribute evaluates to a java.lang.String value. Code of Javascript is run on the pointer button is moved inside the current element.
     
  • onmouseout : This is not a required attribute. This attribute evaluates to a java.lang.String value. Code of Javascript is run on the pointer button is moved out from the current element.
     
  • onmouseover : This is not a required attribute. This attribute evaluates to a java.lang.String value. Code of Javascript is run on the pointer button is moved onto the current element.
     
  • onmouseup : This is not a required attribute. This attribute evaluates to a java.lang.String value. Code of Javascript is run on the pointer button is released over the current element.
     
  • rel : This is not a required attribute. This attribute describes the relationship of current document to the URL specified by this hyperlink. It's values are of link types these link types are the space-separated list of link types.
     
  • rev : This is not a required attribute. This attribute describes the reverse link from the specified URL by this hyperlink to the current document. It's values are of link types these link types are the space-separated list of link types.
     
  • shape : This is not a required attribute. This attribute is used to specifies the shape of this element to be positioned on the screen on the client side image maps. Value of this attribute may be given as default (for entire region), rect ( for the rectangular region), circle ( for the circular region ), and poly ( for the polygonal region).
     
  • style : This is not a required 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 not a required 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 not a required attribute. This attribute is used to specify the tabbing order of this component in which Tab key pressed it has to be selected. Value of this attribute must be an integer within the range 0 - 32767. The component value 0 indicates the first component which is selected in the Tab key press.
     
  • target : This is not a required attribute. This attribute specifies the frame name where the resource is gotten through this hyperlink should be displayed.
  • title : This is not a required attribute. This attribute specifies the text information of the component as a tooltip when the mouse pointer is hover over this link.
  • type : This is not a required attribute. This attribute is used to specify the MIME type (content type) of the resource assigned via this link. for example text/html, image/png, text/css etc.
     
  • binding : This is not a required attribute. This attribute evaluates to a javax.faces.component.UIComponent specified for linking the component with the property of backing bean.

Example :

Here I am giving a simple example which will demonstrate you about the use of JSF 2 h outputLink tag in JSF applications. In this example I have created a JSF view page where I have used this tag with the value attribute into which passed the URL output.xhtml page where I want to go after click on the text.

Directory Structure

input.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 outputLink Example</title>
</h:head>
<h:body>
<f:view>
<h:form>
<h:outputLink value="output.xhtml">output</h:outputLink>
</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 outputLink</title>
</h:head>
<h:body>
<f:view>
<p>Welcome, to JSF 2 h outputLink tutorial</p>
</f:view>
</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>jsfHOutputLink</display-name>
<welcome-file-list>
<welcome-file>input.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/jsfHOutputLink//input.xhtml in the address bar of the web browser.

Output

When you will execute the above code the main page will be look like as follows :

In the above output page the text 'output' is the body link text specified in the body of the tag.

When you will click on the link then the output will be as follows :

Go to Topic «PreviousHomeNext»

Your Comment:


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

 
Tutorial Topics