title: Manipulate Spring MVC model fields for JSP output
body: <p>I have a model like this defined...</p>
  
  <pre><code>public class Product{
    private long timestamp;
    // get/set follows...
  }
  </code></pre>
  
  <p>The timestamp field is fine for the database, since I persist the data via JPA. However, in the JSP output, I don't want to present the timestamp as long, I want to present it as a customized String. I would like to define the long/String conversion in a custom method. </p>
  
  <p>I could convert the timestamp field to DateTime or something, but this is a general question - how is it possible to process model data without modifying the model itself, because it's just for the view? I looked into <a href="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/validation.html" rel="nofollow">Spring Conversion</a> and Formatter SPIs, but that doesn't seem to fit here (Formatter is mainly for user input, Conversion applies to the whole model and I just want to manipulate one field of the model).</p>
  
  <p>I already thought of creating a new object just for the view, passing all the data from the database model and manipulate it there, but there must be a better solution...</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Some additonal code...here is my controller:</p>
  
  <pre><code>@RequestMapping(method=RequestMethod.GET, value="/")
  public ModelAndView getAllProducts() {
      List&lt;Product&gt; products = daoReader.findAllProducts();
  
      ModelAndView mv = new ModelAndView("myproductview");
      mv.addObject("products", products);
  
      return mv;
  </code></pre>
  
  <p>And this is the JSP (simplified):</p>
  
  <pre><code>&lt;c:forEach items="${products}" var="currentproduct"&gt;
          &lt;tr&gt;
              &lt;td&gt;${currentproduct.timestamp}&lt;/td&gt;
              &lt;td&gt;${currentproduct.name}&lt;/td&gt;
          &lt;/tr&gt;
  &lt;/c:forEach&gt;
  </code></pre>