LogikDevelopment
Posts Tagged message tag
The message tags of MyFaces and RichFaces
Working on an application using MyFaces and RichFaces, I had no choice but understand what is the difference between the message tag provided by Myfaces (h:message
) and the message tag overridden by RichFaces (rich:message
).
These tags allow to display information about the first FacesMessage that is assigned to the component referenced by the “for” attribute. The difference is that the RichFaces tag has some extra functionalities such as Ajax rendering, error markers and predefined css class names.
Have a look at the following page for more details: http://livedemo.exadel.com/richfaces-demo/richfaces/message.jsf
This is all nice and well but it is not the only difference. Indeed, the HTML code generated by both these frameworks will also be different!
First of all, let’s see how the tag <h:message styleClass="errormsg" for="element"/>
will be transformed. If there is no message to display, nothing will be generated (which is a good behaviour). However, if a message is present, the tag will be replaced by the following HTML code:
<span class="errormsg">Required.</span>
So far, so good!
But now let’s check what code RichFaces is generating for the tag <rich:message styleClass="errormsg" for="element"/>
.
The following is the code created if there is NO message to render:
<span class="rich-message errormsg" id="form:j_id255"> <span class="rich-message-label"></span> </span>
And here is the code which will replace the RichFaces tag if there is a message to display:
<span class="rich-message errormsg" id="form:j_id255"> <span class="rich-message-label">Required.</span> </span>
As you can see, the main difference is that RichFaces is wrapping the original span
tag into another span
tag. But, it is also generating some code even if there is no message to display! You would ask why is it doing that? The response is simple. The wrapper span element is necessary for RichFaces to Ajax-render the message tag if an error message has to be displayed for the targeting element.
So make sure you don’t put any padding or margin style in your custom CSS class which I called ‘errormsg’ in my example. Otherwise, you might have a gap when you were expecting nothing… (this happened to me) 😉
Ajax, FacesMessage, Html, JSF, message tag, MyFaces, RichFaces
Share this
Archives
- March 2014 (2)
- September 2013 (1)
- August 2013 (1)
- July 2013 (1)
- June 2013 (1)
- February 2013 (1)
- January 2013 (1)
- December 2012 (1)
- September 2012 (1)
- August 2012 (1)
- June 2012 (1)
- May 2012 (1)
- April 2012 (3)
- February 2012 (1)
- December 2011 (3)
- November 2011 (2)
- October 2011 (2)
- September 2011 (2)
- July 2011 (1)
- June 2011 (2)
- May 2011 (2)
- April 2011 (2)
- March 2011 (2)
- February 2011 (2)
- January 2011 (2)
- December 2010 (1)
- November 2010 (2)
- October 2010 (3)
- September 2010 (1)
- August 2010 (2)
- July 2010 (1)
- June 2010 (2)
- May 2010 (3)
- March 2010 (2)
- February 2010 (3)
- January 2010 (2)
- December 2009 (3)
- November 2009 (3)
Tags
Ajax Amazon S3 Arch Linux backup bash benchmarking Bug cron D-Link decryption DNS-313 DNS-323 encryption Html Internet Explorer IOzone Java JavaScript javax.crypto JSF Linux locale Mac OS X Monitoring MyFaces MySQL OAuth onclick OpenSolaris PHP Raspberry Pi RichFaces s3sync Samba shell SQL Server Tomcat Twitter Twitter4J UTF-8 VBScript virtual storage pool Windows Zabbix zpool