This tag is useful in displaying the message related with a particular component. The component for which the error message is to be displayed is decided in for attribute of the tag. You can display summarized message and detailed message for the component. We can use different CSS styles and class with different type of messages on different severity. We can change the format of the message string.
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"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>t:message example</title>
<style type="text/css">
<!--
body{
background-color:#fff2f2;
margin-top:30;
}
-->
</style>
</head>
<body ><center>
<f:view>
<h:form id="form1" >
<h:panelGrid id="pg" columns="2"
style="background-color:#66CCFF;">
<t:outputLabel id="ol1" for="UserName" value="User Name"
style="font-weight:bold"/>
<t:panelGroup>
<t:inputText id="UserName" required="true"/>
<f:verbatim></br></f:verbatim>
<t:message for="UserName" replaceIdWithLabel="true"
style="font-style:Italic;"/>
</t:panelGroup>
<t:outputLabel id="ol2" for="Password" value="Password"
style="font-weight:bold"/>
<t:panelGroup>
<t:inputSecret id="Password" required="true"/>
<f:verbatim></br></f:verbatim>
<t:message for="Password" replaceIdWithLabel="true"
style="font-style:Italic;"/>
</t:panelGroup>
<t:outputText value=" " />
<t:commandButton id="btnSubmit" value="Submit"
action="welcome"
style="border-color:#000000;font-weight:bold"/>
</h:panelGrid>
</h:form>
</f:view>
</center></body>
</html>
|
Rendered Output : This is the first look that a user experiences.

If the user doesn't fill the fields in the form then error messages are rendered as in the figure below :

Html Source Code :
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>t:message example</title>
<style type="text/css">
<!--
body{
background-color:#fff2f2;
margin-top:30;
}
-->
</style>
</head>
<body ><center>
<form id="form1" name="form1" method="post"
action="/tomahawk_tags/pages/message.jsf"
enctype="application/x-www-form-urlencoded">
<table id="form1:pg" style="background-color:#66CCFF;">
<tbody><tr><td><label id="form1:ol1" style="font-weight:bold"
for="form1:UserName">User Name</label></td><td>
<input id="form1:UserName" name="form1:UserName"
type="text" value="" /></br></td></tr>
<tr><td><label id="form1:ol2" style="font-weight:bold"
for="form1:Password">Password</label></td><td><input
type="password" id="form1:Password" name="form1:Password" />
</br></td></tr>
<tr><td> </td><td><input id="form1:btnSubmit"
name="form1:btnSubmit" type="submit" value="Submit"
onclick="if(typeof window.clearFormHiddenParams_form1!='undefined')
{clearFormHiddenParams_form1('form1');}"
style="border-color:#000000;font-weight:bold" /></td></tr>
</tbody></table>
<input type="hidden" name="form1_SUBMIT" value="1" />
<input type="hidden" name="form1:_link_hidden_" />
<input type="hidden" name="form1:_idcl" />
<script type="text/javascript"><!--
function clear_form1(){
clearFormHiddenParams_form1('form1');
}
function clearFormHiddenParams_form1(currFormName){
var f = document.forms['form1'];
f.elements['form1:_link_hidden_'].value='';
f.elements['form1:_idcl'].value='';
f.target='';
}
clearFormHiddenParams_form1();
//--></script><input type="hidden" name="javax.faces.ViewState"
id="javax.faces.ViewState"
value="rO0ABXVyABNbTGphdmEubGFuZy5PYmplY3Q7kM5YnxBzKWwCAAB4cAAAAAN0AAI1
NnB0ABIvcGFnZXMvbWVzc2FnZS5qc3A=" /></form>
</center><!-- MYFACES JAVASCRIPT --> </body> </html> |
This tag contains attributes given below :
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Tomahawk message tag
Post your Comment