JSF - h:commandLink

The h:commandLink tag renders an HTML "anchor" element.
<h:commandLink value = "Page 1" action = "page1" /> 
<a href = "#" onclick = "mojarra.jsfcljs(document.getElementById('j_idt13'), 
   {'j_idt13:j_idt14':'j_idt13:j_idt14'},'');return false">Page 1</a>

id
Identifier for a component
binding
Reference to the component that can be used in a backing bean
rendered
A boolean; false suppresses rendering
styleClass
Cascading stylesheet (CSS) class name
value
A component’s value, typically a value binding
valueChangeListener
A method binding to a method that responds to value changes
converter
Converter class name
validator
Class name of a validator that’s created and attached to a component
required
A boolean; if true, requires a value to be entered in the associated field
Accesskey
A key, typically combined with a system-defined metakey, that gives focus to an element
accept
Comma-separated list of content types for a form
accept-charset
Comma- or space-separated list of character encodings for a form. The accept-charset attribute is specified with the JSF HTML attribute named acceptcharset.
Alt
Alternative text for nontextual elements such as images or applets
border
Pixel value for an element’s border width
charset
Character encoding for a linked resource
coords
Coordinates for an element whose shape is a rectangle, circle, or polygon
dir
Direction for text. Valid values are ltr (left to right) and rtl (right to left)
hreflang
Base language of a resource specified with the href attribute; hreflang may only be used with href.
lang
Base language of an element’s attributes and text
maxlength
Maximum number of characters for text fields
readonly
Read-only state of an input field; text can be selected in a readonly field but not edited
rel
Relationship between the current document and a link specified with the href attribute
rev
Reverse link from the anchor specified with href to the current document. The value of the attribute is a space-separated list of link types
size
Size of an input field
style
Inline style information
tabindex
Numerical value specifying a tab index
target
The name of a frame in which a document is opened
title
A title, used for accessibility, that describes an element. Visual browsers typically create tooltips for the title’s value
type
Type of a link; for example, stylesheet
width
Width of an element
onblur
Element loses focus
onchange
Element’s value changes
onclick
Mouse button is clicked over the element
ondblclick
Mouse button is double-clicked over the element
onfocus
Element receives focus
onkeydown
Key is pressed
onkeypress
Key is pressed and subsequently released
onkeyup
Key is released
onmousedown
Mouse button is pressed over the element
onmousemove
Mouse moves over the element
onmouseout
Mouse leaves the element’s area
onmouseover
Mouse moves onto an element
onmouseup
Mouse button is released
onreset
Form is reset
onselect
Text is selected in an input field
Let us create a test JSF application to test the above tag.
<!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 Tutorial!</title>
   </head>
   
   <body>
      <h2>h:commandLink example</h2>
      <hr />
      
      <h:form>
         <h:commandLink value = "Page 1" action = "page1" />
      </h:form>
   </body>
</html>
Once you are ready with all the changes done, let us compile and run the application as we did in JSF - First Application chapter. If everything is fine with your application, this will produce the following result.

    37 Lectures 
     3.5 hours 

 Chaand Sheikh
 Print
 Add Notes
 Bookmark this page