title: Spring form -- modelAttribute name as java constant
body: <p>in order to not repeat myself in code I've used <code>modelAttribute</code> name as java constant</p>
  
  <pre><code>@Controller
  @RequestMapping("/")
  public class Controller {
      public static final String MODEL_ATTRIBUTE = "myModel";
  
      public String renderPage(Model model) {
          model.addAttribute(MODEL_ATTRIBUTE, ...);
          return "index";
      }
  }
  </code></pre>
  
  <p>Now I import this constant into JSP using scriptlet (I know that scriptlets are bad, but I'm not familiar with better solution).</p>
  
  <pre><code>&lt;%@page contentType="text/html" pageEncoding="UTF-8" %&gt;
  &lt;%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %&gt;
  &lt;%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %&gt;
  
  &lt;%@page import="static com.example.Controller.*" %&gt;
  
  &lt;form:form action="/" modelAttribute="&lt;%= MODEL_ATTRIBUTE %&gt;"&gt;
  
      &lt;form:label path="attr1"&gt;Attribute:&lt;/form:label&gt;
      &lt;form:input path="attr1" /&gt;
  
      &lt;c:forEach items="${???.attr2}" var="item"&gt;
          ...    
      &lt;/c:forEach&gt;
      &lt;input type="submit" /&gt;
  &lt;/form:form&gt;
  </code></pre>
  
  <p>How should I refer to <code>modelAttribute</code> object in the forEach loop? Is there better solution for <a href="http://en.wikipedia.org/wiki/Don%27t_repeat_yourself" rel="nofollow">DRY</a> in Spring forms?</p>