dinsdag 20 oktober 2009

nullpointer for param inside commandlink

The problem started when I added this param to a commandlink like in the code below:
<h:commandLink 
  value="#{item.elementCombinedCode}" 
  action="#{elementFormController.prepareElementAction}">
<f:param name="elementNbr" 
  value="#{item.elementId}" />
</h:commandLink>
With Glassfish version 9.1_01 (build b09d-fcs) I then got this error:
java.lang.NullPointerException
at com.sun.faces.renderkit.RenderKitUtils.getCommandLinkOnClickScript(RenderKitUtils.java:934)
at com.sun.faces.renderkit.html_basic.CommandLinkRenderer.getOnClickScript(CommandLinkRenderer.java:295)
at com.sun.faces.renderkit.html_basic.CommandLinkRenderer.renderAsActive(CommandLinkRenderer.java:357)
at com.sun.faces.renderkit.html_basic.CommandLinkRenderer.encodeBegin(CommandLinkRenderer.java:165)
...
After some investigation I got to this issue stating that you would get this error when the given param value is null. Good news is that it's solved in following versions of glassfish. I quote:

The following will blow up:
<h:commandLink value="Go!">
    <f:param name="test" value="#{null}"/>
</h:commandLink>
The reason is that, while HtmlBasicRenderer.getParamList(UIComponent)
acknowledges that the parameter value may be null, and thus creates a
com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.Param instance with a null
value if the parameter's value was null, the code in
RenderKitUtils.getCommandLinkOnClickScript dereferences the param.value property
without checking whether it is null:
for (Param param : params) {         
            sb.append(',');
            sb.append(param.name.replace("'", "\\\'"));
            sb.append(',');
            sb.append(param.value.replace("'", "\\\'"));            
        }          
Resulting in an NPE.

Geen opmerkingen:

Een reactie plaatsen