PDA

View Full Version : Error in Spring mvcconvention sample


grishester
Oct 11th, 2006, 07:14 PM
Hi everybody,

I'd just like to mention the fact that there is a little error in the sample application, mvcconvention which is inside the Spring 2.0 distribution.

When you try to edit and save one of the recipes, it would not work (it will not redirect to the switchboard/listRecipes.jsp) because there is one tag that should not be in the editRecipe.jsp.

When you enter to the editRecipe.jsp page, the framework keeps in memory the id parameter. If you select the item number 3 (Deep fried battered Hershey bar) and click on Edit, then the HTML code of the following page will be:

<html>
<head><title>Recipes</title></head>

<body>
<form id="recipe" method="post" action="/MVCConvention/editrecipe.htm?id=3">
<input id="id" name="id" type="hidden" value="3"/>

<table>
<tr>
<td>Name:</td>
<td><input id="name" name="name" type="text" value="Deep fried battered Hershey bar"/></td>
<td></td>
</tr>
<tr>
<td colspan="3">

<input type="submit" value="Save Changes"/>
</td>
</tr>
</table>
</form>
</body>
</html>



so the id parameter will be repeated and, on submitting the form, Spring will take it as an array (3,3). In fact, if you add a <form:errors path="*"/> tag in your editRecipe.jsp, you will see the following message:

Failed to convert property value of type [java.lang.String[]] to required type [java.lang.Long] for property 'id'; nested exception is java.lang.NumberFormatException: For input string: "3,3"

So, for the tutorial to work well, you have to comment the line
<form:hidden path="id"/>.

This way the id parameter will not be repeated and it will work fine.

Thanks,

Julien