Magazine
 
Tomahawk Tags

The output below is the result of bad guessing of the number by the user.

7-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 validateCreditCard tag can do this validation. 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” respectively. 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:

 

Oct 2007 | Java Jazz Up | 40
 
previous
index
next
 
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 , 54, 55, 56, 57,

58
, 59, 60, 61, 62, 63 , 64, 65 , 66 , 67 , 68 , 69 , 70, 71, 72, 73, 74, 75, 76, 77, 78,   Download PDF