JSF commandLink Tag

This section illustrates you about the JSF commandLink tag which is rendered as a anchor tag. And this tag behaves as a command button for the form submission.

JSF commandLink Tag

JSF commandLink Tag

    

This section illustrates you about the JSF commandLink tag which is rendered as a anchor tag. And this tag behaves as a command button for the form submission and this tag is also used for the event handling purposes through the backing bean. This tag has text that can be labeled by some external resources like properties file from the message bundle.

Here, you will see more about the commandLink tag of JSF how is it used in JSF programming. There is a program with the complete code of JSF has been given for understanding the procedure of using the tag.

Code Description:

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

<f:view>
<html>
   <head><title>jsf h:commandLink example</title></head>

   <body>
  <h:form>
   <h:commandLink value="Go for list of examples." action="page2" />
  </h:form>
   </body>
</html>
</f:view>

Here, when your run the above program, output will be seen like the following image in which the text "Go for list of examples." is looking like a hypertext. This is not only a anchor tag. This link behaves like a command button. You can perform an action at the specific event.

Rendered Output:

When you run the above example, your JSF tags are converted in to HTML code that is given. Following html source code is for the above written JSF code.

HTML Source Code:

<html>
     <head><title>jsf h:commandLink example</title></head>

     <body>
          <form id="_id0" method="post" action="/h-tags/pages/commandLink/
commandLink.jsf" enctype="application/x-www-form-urlencoded">
               <a href="#" onclick="document.forms['_id0']['_id0:_idcl']
.value='_id0:_id1'; document.forms['_id0'].submit(); return false;">Go
 for list of examples.</a>
	       <input type="hidden" name="_id0" value="_id0" /><input
 type="hidden" name="_id0:_idcl" />
          </form>
    </body>
</html>

This JSF tag has some attributes these explained as follows:

  • accesskey: This attribute set the key for the component through which the component can be accessed. Specified key is also used for transferring focus from one component to the component where it mentioned in with the JSF commandLink tag.
  • action: This is also an attribute of the JSF commandLink tag. This attribute is used for handling events from the backing bean or any other resources to invoke the component when the component is activated by user. This type of action event is completed through a action method of the backing bean class. This method will either return a boolean value true or false by whom the Java Server Faces MVC Framework is designed. And navigations are depended on generated events and actions.
  • actionListener: This attribute sets a method-binding expression with a backing bean. This method handles events.
  • binding: This attribute binds values with backing bean.
  • charset: This attribute sets the character encoding for the document that linked to by the hyperlink.
  • coords: When you are using the link with a client-side image map, this attribute sets the position and the shape of spot on the screen.
  • dir: This attribute set the direction of the text. The value for the attribute is accepted as "LTR" (left to right) or "RTL" (right to left).
  • hreflang: This attribute sets the language code for the resource linked to by the hyperlink.
  • id: This attribute sets the name for the identification of the component. It's value will be unique in the closest naming container.
  • immediate: It's value is a boolean value that indicates for the component events that should be sent to registered event listeners immediately. The immediate attribute allows you to turn off validation for a particular component.
  • lang: It sets the code for the language to be used in the markup generated by this component.
  • onblur: This attribute sets JavaScript code when the component loses the focus.
  • ondblclick: This attribute sets the JavaScript code when the component has been double-clicked over the component.
  • onfocus: This attribute sets the JavaScript code when the component receives focus.
  • onkeydown: This attribute sets the JavaScript code when key is pressed down over the element.
  • onkeypress: This attribute sets the JavaScript code when key is pressed and released over the element or the component.
  • onkeyup: This attribute sets the JavaScript code when key is released over the element or component.
  • onmousedown: Specified JavaScript method is executed when mouse is pressed down over the component.
  • onmousemove: This attribute sets the JavaScript code to executed when the mouse pointer is moved within the component.
  • onmouseout: This attribute sets the JavaScript code to execute when the mouse pointer is moved away from the element.
  • onmouseover: This attribute sets the JavaScript code to execute when the mouse pointer is moved inside the element.
  • onmouseup: This attribute sets the JavaScript code to executed when the mouse pointer is released from the component.
  • rel: This attribute tells you about the relationship between the current document and the document linked to by the hyperlink. It's values are the list of the link types separated by space from each other.
  • rev: This attribute identifies a reserve link from the document linked to by the hyperlink to the current document. It's values are a list of link types separated by space from each other.
  • rendered: This attribute takes a boolean value that indicates for the rendering it or not in the view.
  • shape: This attribute sets the shape of the hotspot for viewing on the screen during the client side image mapping. It's some valid value is "rect" for the rectangular region, "default" for the entire region, "circle" for the circular region and "poly" for the polygonal region.
  • style: If you want ot add any CSS with the component then you can put the style as the value of the attribute. Added CSS will be applied on for the component.
  • styleClass: This attribute holds the CSS class name which is defined in the external style sheet.
  • tabindex: This attribute sets the tab index for the component. When you press the TAB key then the component will be focused after focusing all those components whose tab index is less than the component.
  • target: This attribute set the identification of a frame in which the resource has to be displayed that is linked to by the hyperlink.
  • title: This attribute holds a string value that is shown as a tool-tip text of a component or element.
  • type: This attribute tells the component type whether it is submit type or reset etc.
  • value: This attribute set the display value for the component. It will be directly or any other resources like the backing bean or a message bundle. You can manage the backing bean for the value of the component or element.