Announcement Announcement Module
Collapse
No announcement yet.
tricks to pass a null to a taglib string parameter? (JSP EL converts it to a blank) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • tricks to pass a null to a taglib string parameter? (JSP EL converts it to a blank)

    kind of a brain teaser, and i know only tangentially related to spring,
    but you guys are my favorite, so here goes:

    i'm trying to create a simple jsp tag file (roo style tagx file) to wrap the spring:message tag such that i can default the text parameter.

    the tag file looks something like this:

    Code:
    <jsp:root xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:fn="http://java.sun.com/jsp/jstl/functions"
    	xmlns:spring="http://www.springframework.org/tags" xmlns:form="http://www.springframework.org/tags/form"
    xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0">
    	<jsp:output omit-xml-declaration="yes" />
    
    	<jsp:directive.attribute name="code" type="java.lang.String" required="true" rtexprvalue="true"
    		description="see corrosponding argument for spring:message" />	
    	<jsp:directive.attribute name="var" type="java.lang.String" required="false" rtexprvalue="true"
    		description="see corrosponding argument for spring:message" />
    
    	<c:set var="text" value="{${code}}" />
    
            <spring:message code="${code}" text="${text}" var="${var}"/>
    
    </jsp:root>
    the issue is that if 'var' isn't passed, it comes in as null, but '${var}' converts it to a blank '',
    and passes it to spring:message, and spring:message behaves undesirably with a blank 'var' arg vs. a null 'var' arg...

    the only way i can currently get the desired effect is to conditionally call spring:message with no 'var' arg,
    but i was wondering if any one knew any sneaky tricks to force a null past the default behavior of JSP EL to convert nulls into blanks...

    thanks,
    tony.

  • #2
    i just realized this is harder than it looks. the "var" set in the context of the tag file isn't visible in the context of the caller upon return from the execution of the tag.

    it seemed like a good idea at the time

    Comment

    Working...
    X