title: Spring MVC: how to display formatted date values in JSP EL
body: <p>Here's a simple value bean annotated with Spring's new (as of 3.0) convenience  <code>@DateTimeFormat</code> annotation (which as I understand replaces the pre-3.0 need for custom <code>PropertyEditor</code>s as per <a href="https://stackoverflow.com/q/12544479/225217">this SO question</a>):</p>
  
  <pre><code>import java.time.LocalDate;
  import org.springframework.format.annotation.DateTimeFormat;
  
  public class Widget {
    private String name;
  
    @DateTimeFormat(pattern = "MM/dd/yyyy")
    private LocalDate created;
  
    // getters/setters excluded
  }
  </code></pre>
  
  <p>When biding the values from a form submission to this widget, the date format works flawlessly.  That is, only date strings in the <code>MM/dd/yyyy</code> format will convert successfully to actual <code>LocalDate</code> objects. Great, we're halfway there.</p>
  
  <p>However, I would also like to be able to also display the created <code>LocalDate</code> property in a JSP view in the same <code>MM/dd/yyyy</code> format using JSP EL like so (assuming my spring controller added a widget attribute to the model):</p>
  
  <pre><code>${widget.created}
  </code></pre>
  
  <p>Unfortunately, this will only display the default <code>toString</code> format of <code>LocalDate</code> (in <code>yyyy-MM-dd</code> format).  I understand that if I use spring's form tags the date displays as desired:</p>
  
  <pre><code>&lt;form:form commandName="widget"&gt;
    Widget created: &lt;form:input path="created"/&gt;
  &lt;/form:form&gt;
  </code></pre>
  
  <p>But I'd like to simply display the formatted date string without using the spring form tags.  Or even JSTL's <code>fmt:formatDate</code> tag.</p>
  
  <p>Coming from Struts2, the <code>HttpServletRequest</code> was wrapped in a <a href="http://struts.apache.org/maven/struts2-core/apidocs/org/apache/struts2/dispatcher/StrutsRequestWrapper.html" rel="noreferrer"><code>StrutsRequestWrapper</code></a> which enabled EL expressions like this to actually interrogate the OGNL value stack.  So I'm wondering if spring provide something similar to this for allowing converters to execute?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I also realize that when using spring's <code>eval</code> tag the date will display according the pattern defined in the <code>@DateTimeFormat</code> annotation:</p>
  
  <pre><code>&lt;%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %&gt;
  &lt;spring:eval expression="widget.created"/&gt;
  </code></pre>
  
  <p>Interestingly, when using a custom <code>PropertyEditor</code> to format the date, this tag does NOT invoke that <code>PropertyEditor</code>'s <code>getAsText</code> method and therefore defaults to the <code>DateFormat.SHORT</code> as <a href="http://docs.spring.io/spring/docs/current/spring-framework-reference/html/validation.html#format-configuring-formatting-globaldatetimeformat" rel="noreferrer">described in the docs</a>.  In any event, I'd still like to know if there is a way to achieve the date formatting without having to use a tag--only using standard JSP EL.</p>