Tomahawk
validateRegExpr tag

This tag is used to validate a string entered
by the user. If we want the user to enter a specific pattern of string
then we can set the pattern for that component. For example, we have an
input field and we want the user to enter a number that consists of any
number with "1" in the beginning but only one "2" at
the last. So for this Tomahawk provides a tag validateRegExpr which has
pattern attribute that is used to specify the pattern to be followed by
the user to input the string in the box. If the entered value is not
following the pattern 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:validateRegExpr example</title>
<style type="text/css">
<!--
body{
background-color:#fff2f2;
margin-top:30;
}
-->
</style>
</head>
<body >
<h:form>
<t:outputText value="Enter any number starting
from any number of '1's but '2' at last. "/></p>
<t:inputTextHelp id="regExprValue" helpText="Like
:12, 112, 11112" required="true">
<t:validateRegExpr pattern="1*2" message="Type correct Number."/>
</t:inputTextHelp>
<t:message for="regExprValue"/></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 user enters a wrong input then the
message is displayed like below :

Html Source Code :
<html>
<head>
<script type="text/javascript"
src="/tomahawk_tags/faces/myFacesExtensionResource/
org.apache.myfaces.renderkit.html.util.MyFacesResourceLoader/11857935/
inputTextHelp.HtmlTextHelpRenderer/inputTextHelp.js"><!--
//--></script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>t:validateRegExpr 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/validateRegExpr.jsf"
enctype="application/x-www-form-urlencoded">
Enter any number starting from any number of '1's but '2' at last.
</p>
<input id="_idJsp0:regExprValue" name="_idJsp0:regExprValue"
type="text" onfocus="resetHelpValue('Like :12, 112, 11112',
'_idJsp0:regExprValue')"
onclick="resetHelpValue('Like :12, 112, 11112', '_idJsp0:regExprValue')"
value="Like :12, 112, 11112" />
</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="rO0ABXVyABNbTGphdmEubGFuZy5PYmplY3Q7kM5YnxBzKWwCAAB4cAAA
AANzcgBHb3JnLmFwYWNoZS5teWZhY2VzLmFwcGxpY2F0aW9uLlRyZWVTdHJ1Y3R
1cmVNYW5hZ2VyJFRyZWVTdHJ1Y3RDb21wb25lbnRGWRfYnEr2zwIABF
...........
..........." />
</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.
- pattern : This attribute is used to
specify the pattern that is to be followed while inputting the text.

|