Magazine
 
Tomahawk Tags

If the user enters a wrong input then the message is displayed like below:

6-Tomahawk validateEqual tag

This tag is used to validate the value against the other component. In the for attribute we specify the id of the other component whose value is compared to the value of the component for which the validation is performed. If both are same then no error otherwise it displays the validation message. We can render the validation message by the use of message, detailMessage and summaryMessage attributes.

Code Description:

In this example, we have taken a hidden field with value “999” and one more input component where the user is asked to guess the number. If both matches then next page are rendered otherwise validation message “Try again...” is displayed in the same page.

<%@ 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;
harset=iso-8859-1">
<title>t:validateEqual example</title>
<style type=”text/css”>
<!—
body{
background-color:#fff2f2;
margin-top:30;
}
—>
</style>
</head>
<body >
<h:form>
<center>
<t:panelGrid columns=”1" style=”fontweight:
bold;” width=”40%”>
<t:inputHidden id=”ih” value=”999" />
<t:outputText value=”Can you guess the
number?” />
<t:panelGroup>
<t:inputText id=”number” required=”true”>
<t:validateEqual for=”ih”
message=”Try again.......”/>
</t:inputText>
<f:verbatim></br></f:verbatim>
<t:message for=”number”/>
</t:panelGroup>
<t:commandButton id=”cb”
image=”images/submit_button.gif”
action=”welcome”/>
</t:panelGrid>
</center>
</h:form>
</body>
</html>
</f:view>

Rendered Output:

Oct 2007 | Java Jazz Up | 39
 
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