Tomahawk commandLink tag

This tag behaves like a command button in a form. This tag can also be used for the event handling purposes through the backing bean. This tag has a value attribute that can be assigned to some text which carries to the next resource when we click on the

Tomahawk commandLink tag

Tomahawk commandLink tag

    

This tag behaves like a command button in a form. This tag can also be used for the event handling purposes through the backing bean. This tag has a value attribute that can be assigned to some text which carries to the next resource when we click on the text. We can associate the component with the property of the backing  bean and any method can be called on any particular event on the link.

Code Description : 

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>t:commandLink example</title>
<style type="text/css">
<!--
body{
background-color:#fff2f2;
margin-top:30;
}
-->
</style>
</head>
<body ><center>
<f:view>
   <h:form id="form1" >
   <t:outputLabel id="emailIdLabel" value="Enter Email ID :"
       style="font-size:18px"/>
   <t:inputText id="emailId" required="true"/><h:message 
       for="emailId" style="font-style:Italic; color:green"/></br>
   <t:commandLink id="cmdLink"  value="Send me source code." 
         style="font-weight:bold; color:green" action="welcome" />
   </h:form>
</f:view>
</center></body>
</html>

Rendered Output :

Html Source Code :

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; 
             charset=iso-8859-1">
<title>t:commandLink example</title>
<style type="text/css">
<!--
body{
background-color:#fff2f2;
margin-top:30;
}
-->
</style>
</head>
<body ><center>
  <form id="form1" name="form1" method="post" 
      action="/tomahawk_tags/pages/commandLink.jsf" 
      enctype="application/x-www-form-urlencoded">
    <label id="form1:emailIdLabel" style="font-size:18px">
              Enter Email ID :</label>
	<input id="form1:emailId" name="form1:emailId" 
               type="text" value="" /></br>
	<script type="text/javascript"><!--
	function oamSetHiddenInput(formname, name, value)
	{
	var form = document.forms[formname];
	if(typeof form.elements[name]=='undefined'){
          var newInput = document.createElement('input');
          newInput.setAttribute('type','hidden');
	  newInput.setAttribute('name',name);
	  newInput.setAttribute('value',value);
          form.appendChild(newInput);
	}
	else{
	  form.elements[name].value=value;
	}
  }
        function oamClearHiddenInput(formname, name, value){
	  var form = document.forms[formname];
	  if(typeof form.elements[name]!='undefined'){
		form.elements[name].value=null;
	}
  }
       function oamSubmitForm(formName, linkId, target, params){
          var clearFn = 'clearFormHiddenParams_'+
                formName.replace(/-/g, '\$:').replace(/:/g,'_');
          if(typeof eval('window.'+clearFn)!='undefined'){
                eval('window.'+clearFn+'(formName)');
	}
       var oldTarget = '';
          if((typeof target!='undefined') && target != null){
             oldTarget=document.forms[formName].target;
             document.forms[formName].target=target;
	}
	  if((typeof params!='undefined') && params != null){
             for(var i=0; i<params.length; i++){
                oamSetHiddenInput(formName,params[i][0], params[i][1]);
	}
  }
       oamSetHiddenInput(formName,formName +':'+'_idcl',linkId);
       if(document.forms[formName].onsubmit){
          var result=document.forms[formName].onsubmit();
          if((typeof result=='undefined')||result){
             document.forms[formName].submit();
	   }
       }
       else {
          document.forms[formName].submit();
	}
        if(oldTarget==null) oldTarget='';
	document.forms[formName].target=oldTarget;
	if((typeof params!='undefined') && params != null){
           for(var i=0; i<params.length; i++){
               oamClearHiddenInput(formName,params[i][0], params[i][1]);
               }
        }
          oamClearHiddenInput(formName,formName +':'+'_idcl',
                                linkId);return false;
   }
//--></script><a href="#" onclick="return 
        oamSubmitForm('form1','form1:cmdLink');"
        id="form1:cmdLink" style="font-weight:bold; color:green">
                   Send me source code.</a>
	<input type="hidden" name="form1_SUBMIT" value="1" />
        <input type="hidden" name="form1:_link_hidden_" />
        <input type="hidden" name="form1:_idcl" />
   <script type="text/javascript"><!--
	function clear_form1(){
          clearFormHiddenParams_form1('form1');
	}
	function clearFormHiddenParams_form1(currFormName){
	   var f = document.forms['form1'];
           f.elements['form1:_link_hidden_'].value='';
	   f.elements['form1:_idcl'].value='';
	   f.target='';
	}
	clearFormHiddenParams_form1();
//--></script><input type="hidden" name="javax.faces.ViewState" 
              id="javax.faces.ViewState" 
value="rO0ABXVyABNbTGphd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QmluZGluZwAAAAAAAAAAAAAAeHB0AAd3ZWxjb21l
cHB0ABRTZW5kIG1lIHNvdXJjZSBjb2RlLnBwcHBwcHBwcHBwcHBwcHBwcHBwcHQAHWZvbnQ
td2VpZ2h0OmJvbGQ7IGNvbG9yOmdyZWVucHBwcHBwcHBwcHBwcHB4eHEAfgAi" /></form>
</center><!-- MYFACES JAVASCRIPT -->
</body>
</html>

This tag contains attributes given below :

  • id : This is the value which is used to uniquely identify the component within the closest container like form or subview. The main thing to remember is that its value must be a static value.
  • binding : This attribute is used to specify the property of the backing bean with which this component instance is to be bound.
  • rendered : Its default value is true. If  this attribute is set to true then this component is presented in the page to the user. If false, then this component is not rendered.
  • immediate : This attribute is a boolean attribute that is used to identify the phase during which the value change event should be fired. In normal processing of the event, if immediate attribute is not set to true, the value change event is fired during the invoke application phase but if immediate attribute is set to true then the event is fired at the end of apply request value phase.
  • action : This attribute takes method binding EL expression that specifies which backing bean method is to be invoked when the user clicks the link.
  • actionFor : The actionFor attribute takes a comma-separated list of subForm IDs for which validation and modal update should take place when this command is executed.
  • actionListener : The actionListener attribute is used to assign an action listener method from backing bean that performs the specific operation.
  • value : The initial value of the component is set to this attribute.
  • dir : It is used to set the direction of the text to be displayed. It can take two values LTR(left to right) and RTL (right to left). 
  • lang : It is used to set the base language of the component when displayed.
  • style : It is used to set the CSS style definition for the component.
  • title : It is the standard html attribute. It is used to set the tooltip text for this component.
  • styleClass : It is used to set the CSS class for the component. It is same as html class attribute.
  • onclick : Script to be invoked when the element is clicked. 
  • ondblclick : It is used for Java Script code to be invoked when the element is double-clicked. 
  • onmousedown : It is used for Java Script code to be invoked when the pointing device is pressed over this element. 
  • onmouseup : It is used for Java Script code to be invoked when the pointing device is released over this element. 
  • onmouseover : It is used for Java Script code to be invoked when the pointing device is moved into this element. 
  • onmousemove : It is used for Java Script code to be invoked when the pointing device is moved while it is in this element. 
  • onmouseout : It is used for Java Script code to be invoked when the pointing device is moved out of this element. 
  • onkeypress : It is used for Java Script code to be invoked when a key is pressed over this element. 
  • onkeydown : It is used for Java Script code to be invoked when a key is pressed down over this element.
  • onkeyup : It is used for Java Script code to be invoked when a key is released over this element. 
  • accesskey : This is standard html attribute. It is used to set the access key for the element which is used to send the focus to the element when pressed. 
  • charset : This attribute is used to specify the character encoding of the resource that is linked to the hyperlink.
  • tabindex : This is a standard html attribute. It is used to set the order of receiving the focus on the movement of TAB key by the user.
  • onblur : This attribute sets JavaScript code to execute when the component loses the focus.
  • onfocus : This attribute sets JavaScript code to execute when the component receives the focus.
  • type : This attribute tells the component type whether it is submit type or reset etc.
  • target : This attribute is used to specify the name of the frame where the resource linked to the hyperlink is to be displayed.
  • coords : This attribute specifies the coordinates of the region within a client side image map where the link is to be used..
  • hreflang : This attribute specifies the language code of the resource linked to the hyperlink.
  • rel : This attribute is used to specify the relationship between the current document to the destination resource linked to the hyperlink. In other words, it defines the meaning of the referred resource for the actual document.
  • rev : This attribute is used to specify the relationship from the resource pointed by the link to the current document. In other words, it defines the meaning of the actual document for the referred resource.
  • shape : This attribute sets the shape of a region in a client side image map. The values valid for this attribute are default, rect (rectangular region), circle (circular region) and  poly (polygonal region). By default it takes entire region. 
  • enabledOnUserRole : If the current user has one of the roles listed in the enabledOnUserRole attribute then enabling or disabling of the component is decided on the base of "disabled" attribute. If disabled attribute is set to true then component is disabled otherwise enabled. If the user is not in the above list then the component is rendered disabled.
  • visibleOnUserRole : If the current user has one of the roles listed in the visibleOnUserRole attribute then processing of the component is decided on the base of "rendered" attribute. If the rendered attribute is set to true then component is not rendered otherwise displayed  on the page. On the other hand if the current user is not in the above list then the component is not processed.
  • forceId : This is a boolean attribute with default value false. If this attribute is set to true, the tag is forced to render the id for the component exactly as mentioned in the id attribute of the tag. The benefit of this attribute is that we can reference component by id in the javascript. If we don't use this attribute with the true value then the id for the component is presented in different format.
  • forceIdIndex : This is a boolean attribute with default value true. If this value is true then the the component displays the index number in its id value if the component is in a list. If this attribute is set to false then this component will not append index number as suffix . If forcrId is set to false then its value is ignored.
  • disabled : Its a boolean attribute. This is used to disable the element to receive focus, when it is set to true. 
  • disabledStyle : This attribute is used to specify a CSS style to be applied when disabled attribute is set to true.
  • disabledStyleClass : This attribute is used to specify a CSS class to be applied when disabled attribute is set to true.