Announcement Announcement Module
Collapse
No announcement yet.
Form binding to a Map<String, Double[]> with JSP? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Form binding to a Map<String, Double[]> with JSP?

    Hey all,
    Im having some issues binding a form to my command object. The field in particular is this:

    Code:
    Map<String, Double[]> measureMap = new LinkedHashMap();
    I then populate the map with a string key, and the doubles. It is rendered as a table in the view. It works fine to display, buy trying to make the fields editable does not:


    Code:
    <c:forEach items="${measureMap}" var="map" varStatus="idx">
    	<tr>
    		<td>${map.key}</td>
    		<c:forEach items="${map.value}" var="datum" varStatus="idy">
    			<td><form:input value="${datum}" path="measureMap['${map.key}'][${idy.count}]" /></td>
    		</c:forEach>
    	</tr>
    </c:forEach>
    I get the following error:
    Code:
    org.springframework.beans.NullValueInNestedPathException: Invalid property 'measureMap[Square Footage]' of bean class [com.stuff.esm.web.sites.SiteFormBean]: Could not instantiate property type [java.lang.Double] to auto-grow nested property path: java.lang.InstantiationException: java.lang.Double
    Any idea what I am doing wrong here? Thank you in advance!

  • #2
    Two comments, the first is that you should mention the version of Spring mvc you're using. Also, I suspect you might want to search for existing JIRA issues on this topic. This is an issue I've run into in the past - and the version matters a lot.

    Comment


    • #3
      Thanks for the response. I am using Spring 3.0.5 with spring-webmvc at the same version.
      I got passed the first error. The mistake was here:

      Code:
      <c:forEach items="${map.value}" var="datum" varStatus="idy">
      			<td><form:input value="${datum}" path="measureMap['${map.key}'][${idy.count}]" /></td>
      </c:forEach>
      Where it should have been:

      Code:
      <td><form:input value="${datum}" path="measureMap['${map.key}'][${idy.index}]" /></td>
      The forEach varstatus count starts at 1, and index starts at 0. Doh. So what was happening is an index out of bounds problem. My problems are not over, however. When trying to submit the form, I now get this error:

      Code:
      Invalid property 'measureMap[Occupancy][0]' of bean class [com.stuff.esm.web.sites.SiteFormBean]: Cannot access indexed value in property referenced in indexed property path 'measureMap[Occupancy][0]': returned null
      I set a breakpoint at the form bean setMeasureMap() method and notice that the incoming object is null, even though all the post parameters are correct. Argh. I'm starting to think I might give up on trying to bind to a map, and try some more dangerous, ugly approach using lists. I will also take a look on Jira. Anyone else have any suggestions?
      Last edited by Fingel; Nov 11th, 2011, 03:20 PM.

      Comment

      Working...
      X