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 is 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; charset=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="font-weight: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 :
The output below is the result of bad guessing of the number by the user.
Html Source Code :
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>t:validateEqual 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/validateEqual.jsf" enctype="application/x-www-form-urlencoded"> <center> <table width="40%" style="font-weight:bold;"> <tbody><tr><td> <input type="hidden" id="_idJsp0:ih" name="_idJsp0:ih" value="999" /> </td></tr> <tr><td>Can you guess the number?</td></tr> <tr><td> <input id="_idJsp0:number" name="_idJsp0:number" type="text" value="12" /></br> </td></tr> <tr><td><input id="_idJsp0:cb" name="_idJsp0:cb" type="image" src="images/submit_button.gif" onclick="if(typeof window.clearFormHiddenParams__idJsp0!='undefined') {clearFormHiddenParams__idJsp0('_idJsp0');}" /></td></tr> </tbody></table> </center><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="rO0ABXVyABNbTGphdmEubGFuZy5PYmplY3 Q7kM5YnxBzKWwCAAB4cAAAAAN0AAIyMHB0ABgvcGFnZXMvdmFsaWRhdGVFcXVhbC5qc3A=" /> </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.
- for : This attribute specifies the id of the foreign component which is used for equality.