Spring Framework
  1. Spring Framework
  2. SPR-7459

spring:eval displays 'null' when expression evaluates to null

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Complete
    • Affects Version/s: 3.0.3
    • Fix Version/s: 3.0.4
    • Component/s: Web
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      When the expression in a spring:eval tag evaluates to null, the string 'null' is displayed. I think the right behaviour would be an empty string because that would be consistent with the behaviour of JSP EL and spring:bind.

        Activity

        Hide
        Florian Fankhauser added a comment -

        I use this custom tag as workaround:

        <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
        <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
        <%@ attribute name="expression" required="true"rtexprvalue="false" %>

        <spring:eval expression="$

        {expression}" var="value" />
        <c:if test="${value != null}">
        <spring:eval expression="${expression}

        " />
        </c:if>

        Show
        Florian Fankhauser added a comment - I use this custom tag as workaround: <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> <%@ attribute name="expression" required="true"rtexprvalue="false" %> <spring:eval expression="$ {expression}" var="value" /> <c:if test="${value != null}"> <spring:eval expression="${expression} " /> </c:if>
        Hide
        Juergen Hoeller added a comment -

        Good point - that null rendering was an accident. Fixed for 3.0.4, rendering an empty String in the null case now.

        Juergen

        Show
        Juergen Hoeller added a comment - Good point - that null rendering was an accident. Fixed for 3.0.4, rendering an empty String in the null case now. Juergen
        Hide
        Keith Donald added a comment -
        Show
        Keith Donald added a comment - For reference, this issue was originally reported here: http://stackoverflow.com/questions/3457134/how-to-display-a-formatted-datetime-in-spring-mvc-3-0

          People

          • Assignee:
            Juergen Hoeller
            Reporter:
            Florian Fankhauser
            Last updater:
            Trevor Marshall
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Days since last comment:
              3 years, 36 weeks, 5 days ago