Home Jsf Apache-myfaces-tomahawk Tomahawk validateCreditCard tag
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Tomahawk validateCreditCard tag

Advertisement
This tag is used to validate a Credit Card Number entered by the user.

Tomahawk validateCreditCard tag

        

This tag is used to validate a Credit Card Number entered by the user. If we want the user to enter a valid Credit Card Number then this validation can be done by this tag. If we don't want to allow any of the "American Express","Visa""mastercard" or "Discover" then we can set value false for the attributes "ameex","visa""mastercard" and "discover". If we don't want to allow anyone then we can set value true for the attribute "none". If the entered value is not a valid then we can display the message of our interest by using "message" attribute.

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

<f:view>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>t:validateCreditCard example</title>
<style type="text/css">
<!--
body{
background-color:#fff2f2;
margin-top:30;
}
-->
</style>
</head>
<body >
<h:form>
<t:outputText value="Credit Card Number:"/>
<h:inputText id="creditCardNumber" required="true">
<t:validateCreditCard message="Invalid Credit Card number."/>
</h:inputText>
<t:message for="creditCardNumber"/></p>
<t:commandButton id="cb" image="images/submit_button.gif"
                         action="welcome"/>
</h:form>
</body>
</html>
</f:view>

Rendered Output :
This is the output of the above code :

 

If the number entered by the user is not valid then error message is displayed like below :

Html Source Code :

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
 charset=iso-8859-1">
<title>t:validateCreditCard example</title>
<style type="text/css">
<!--
body{
background-color:#fff2f2;
margin-top:30;
}
-->
</style>
</head>
<body >
<form id="_idJsp0" name="_idJsp0" method="post"
      action="/tomahawk_tags/pages/validateCreditCard.jsf"
      enctype="application/x-www-form-urlencoded">
Credit Card Number:
<input id="_idJsp0:creditCardNumber" name="_idJsp0:creditCardNumber"
type="text" value="" />
</p>
<input id="_idJsp0:cb" name="_idJsp0:cb" type="image"
src="images/submit_button.gif" 
onclick="if(typeof window.clearFormHiddenParams__idJsp0!='undefined')
{clearFormHiddenParams__idJsp0('_idJsp0');}" />
<input type="hidden" name="_idJsp0_SUBMIT" value="1" />
<input type="hidden" name="_idJsp0:_link_hidden_" />
<input type="hidden" name="_idJsp0:_idcl" />
<script type="text/javascript"><!--

	function clear__5FidJsp0()
	{
		clearFormHiddenParams__idJsp0('_idJsp0');
	}
	
	function clearFormHiddenParams__idJsp0(currFormName)
	{
		var f = document.forms['_idJsp0'];
		f.elements['_idJsp0:_link_hidden_'].value='';
		f.elements['_idJsp0:_idcl'].value='';
		f.target='';
	}
	
	clearFormHiddenParams__idJsp0();
//--></script><input type="hidden" name="javax.faces.ViewState"
 id="javax.faces.ViewState" value="rO0ABXVyABNbTGphdmEubGFuZy5P
YmplY3Q7kM5YnxBzKWwCAAB4cAAAAANzcgBHb3JnLmFwYWNoZS5teWZhY2VzLmF
wcGxpY2F0aW9uLlRyZWVTdHJ1Y3R1cmVNYW5hZ2VyJFRyZWVTdHJ1Y3RDb21wb2
5lbnRGWRfYnEr2zwIABFsACV9jaGlsZHJlbnQASltMb3JnL2FwYWNoZS9teWZhY
2VzL2FwcGxpY2F0aW9uL1RyZWVTdHJ1Y3R1cmVNYW5hZ2VyJFRyZWVTdHJ1Y3RDQ
..........
.........." />
</form>
<!-- MYFACES JAVASCRIPT -->
</body>
</html>

This tag contains attributes given below :

  • message : This attribute specifies the alternative validation message. The message written in this tag is rendered if validation fails.
  • detailMessage : This attribute specifies the alternative validation message. 
  • summaryMessage : This attribute specifies the alternative validation message.
  • none : This is the boolean attribute with default value "false". If this value is true then no card will be accepted.
  • amex : This is the boolean attribute with default value "true ". If it is true then this validator can validate "American Express" credit cards.
  • visa : This is the boolean attribute with default value "true ". If it is true then this validator can validate "Visa" credit cards.
  • mastercard : This is the boolean attribute with default value "true ". If it is true then this validator can validate "Mastercard"  credit cards.
  • discover : This is the boolean attribute with default value "true". If it is true then this validator can validate "Discover" credit cards.
Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 9, 2009

Related Tutorials

Ask Questions?    Discuss: Tomahawk validateCreditCard tag  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com