Archive for the ‘Uncategorized’ Category

Marker-only validation error with RichFaces

Monday, January 12th, 2009

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”).

Java remote debugging

Thursday, July 31st, 2008

This one was evil. I have an Windows XP box with a Virtual Box installed and a virtualized Xubuntu. I have a Java process running on Windows and my NetBeans is on Xubuntu, and I wanted to debug that Java process. An ugly problem, but it was really easy to solve. I’ve just added this option to the process JVM parameters:

-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=6543,server=y,suspend=n

After this, I can use NB’s “Attach Debugger” feature to connect to the remote JVM. Works like a charm!

java.lang.OutOfMemoryError: Java heap space

Monday, April 14th, 2008

Another easy one that I always forget the recipe. If a Java-based application throws a OutOfMemoryError, you can solve the problem by giving it more memory. Just pass one of these command-line arguments to java.exe:

  • -Xms256m - Java VM will start with a heap of 256mb.
  • -Xmx512m - Java VM will have a maximum heap of 512mb.
  • -XX:PermSize=128m - The permgen space will start with 128mb. This is needed when application instantiates a lot of small objects. It can be explained as the “FAT” (or “EXT3″) of the objects.
  • -XX:MaxPermSize=256m - The permgen space will have a maximum of 256mb.