JSF 2 h link

JSF 2 h link


Posted in : Java Posted on : July 25, 2012 at 10:58 AM Comments : [ 0 ]

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

JSF 2 h link

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

<h:link> tag is rendered to the HTML <a> tag. The 'value' attribute of this tag specifies the link's text and the 'outcome' attribute decides the navigation case i.e. the target URL. The outcome value is rendered to the 'href' attribute of <a> tag. If any of the child parameter is used inside this tag, value of this param will also be determined as the value of 'href'.

Attributes of JSF 2 <h:link>

  • id : This is not a required attribute. This attribute acted as a component's identifier. If this attribute is used it makes the component uniquely identifiable inside it's closest parent.

  • includeViewParams : This is not a required attribute. This attribute evaluates to a boolean value which specifies that whether or not to include the page parameters to the target URI.

  • outcome : This is a required attribute. This attribute is used to specifies the target page that decides the navigation case.
  • 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 current value of the component as link's text.
  • 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.

  • 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.
  • fragment : This is not a required attribute. This is a page fragment identifier which should become focused on rendering of the target page. This fragment value is added at the end of the target URL followed by hash (#). # is a part of standard URL syntax.
  • 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 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

An example is being given here for you which will demonstrate you about how to use the JSF <h:link> tag in a JSF applications. To demonstrate the reader of this tutorial about how to use this tag in JSF applications I have created the two JSF pages into one of which i.e in input.xhtml page I have used this tag and used the 'outcome' attribute to complete the navigation case. When this link will be clicked the output page i.e. output.xhtml page will be rendered.

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">

<head>
<title>JSF 2 h link tag</title>
</head>
<h:body>
<f:view>
<p>To read about the JSF 2 h:link tag 
<h:link value="click here" outcome="output" /> </p>
</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">

<head>
<title>JSF 2 h link tag</title>
</head>
<body>
<f:view>
<p>Welcome, Reader here you will learn about the 
JSF 2 h:link tag.</p>
<p><b>JSF 2 tag is rendered to the HTML anchor(a) tag.</b></p>
</f:view>
</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>jsfHLink</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/jsfHLink/input.jsf 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 input.xhtml page will be viewed as follows :

2. When you will clicked on the give link 'click here' then the output.xhtml page will be viewed as follows :

And in the HTML source code this tag will be showed after rendering the input.xhtml is as follows :

<!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">

<head>
<title>JSF 2 h link tag</title>
</head><body>
<p>To read about the JSF 2 h:link tag 
<a href="/jsfHLink/output.jsf">click here</a> </p></body>
</html>
Go to Topic «PreviousHomeNext»

Your Comment:


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

 
Tutorial Topics