Extreme Java When vanilla Java is not enough

12Jan/090

Marker-only validation error with RichFaces

I've made a simple JSP 2.1 tag file to show only a small icon on my validation errors (and a tooltip to show message details). This is the .tag file:

<%@ tag pageEncoding="UTF-8" %>
<%@ attribute name="field" required="true" deferredValue="true" %>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<%@ taglib prefix="a4j" uri="http://richfaces.org/a4j" %>
<%@ taglib prefix="rich" uri="http://richfaces.org/rich" %>
<rich:message for="#{field}" showSummary="false" showDetail="false">
  <f:facet name="errorMarker">
    <a4j:outputPanel>
      <h:graphicImage value="path-to-bullet"/>
      <rich:toolTip>
        <rich:message for="#{field}"/>
      </rich:toolTip>
    </a4j:outputPanel>
  </f:facet>
</rich:message>

It can be used like this:

<tags:errorMessages field="id-of-the-field"/>

Instead of showing a big chunk of text, your webdesigner will only deal with a small bullet that will show a nice tooltip with the full message. Some "catches":

  • <rich:message tooltip="true"> does not show tooltip if you disable both summary and details;
  • Since "rich:toolTip" can't work with "h:panelGrid", the "a4j:outputPanel" will show the tooltip without adding any extra visual effect (like "rich:panel" does);
  • The inner "rich:message" will render the message inside the tooltip (notice that outer "rich:message" renders only the marker, because summary and details are "off").

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

(required)


*

No trackbacks yet.