LogikDevelopment
Posts Tagged FacesMessage
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 id="bookingform:j_id255" class="rich-message errormsg">
<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
Tags
a4j:poll Ajax AjaxStateManager ArrayIndexOutOfBoundsException bash Bug BUILD_BEFORE_RESTORE compression COMPRESS_STATE_IN_SESSION cron Facelets Hibernate Hibernate MBean Html Internet Explorer Java JavaScript JExcelAPI JMX Remote JSF JXL Linux locale memory Monitoring MyFaces MySQL No saved view state old browsers onclick Return key RichFaces root context session time out shell SKIP_COMMENTS state manager Tomcat UTF-8 VBScript ViewExpiredException Windows WritableFont Zabbix ZapcatArchives
- 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)