Reputation: 113
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NumberFormatException: For input string: ""
I'm trying to build a web app using only annotations, java, JSPs, spring data, spring mvc, and mongo db.
I've got things mostly working, however when I tried to create a JSP form with multi select lists, I'm getting the title error.
I'm trying to create an agent object and save it to the mongodb database. The multi select boxes are passing back string IDs for the objects that were selected. The agent object has lists that need to be populated with the multi select lists.
Here is the response data from chrome dev tools:
id: name:Test1 type:MOB
attributeList[]:687a1964-4179-4631-832b-e23b34300840
personalityTraitList[]:8b321f3c-6398-4bc4-afc6-e6c7e4a6a3e3
skillList[]:53090226-0f54-4121-90c0-4d3a188aa5f8
triggerList[]:923048ef-7a4d-42e3-8691-2d2e9603e79b
behaviorTreeList[]:84966b7a-fb53-4f64-be2a-203ae3743250
Here is the html for the first multi select box. They are all the same.
<td align="left">
<select size="10" id="selectedAttributes" multiple="multiple" name="attributeList[${attribute.id}]" style="width: 130px;"></select>
</td>
Here is the controller save request mapping:
@RequestMapping(value = "/AgentManager/save", method = RequestMethod.POST)
public View createAgent(@ModelAttribute Agent agent, ModelMap model)
{
if(StringUtils.hasText(agent.getId()))
{
agentService.updateAgent(agent);
} else
{
agentService.addAgent(agent);
}
return new RedirectView("/MotherNatureEmulator/AgentManager");
}
The agent service will create a random UUID if the ID field is empty when going to save the agent.
Here is the stack trace:
java.lang.NumberFormatException: For input string: "" java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) java.lang.Integer.parseInt(Integer.java:504) java.lang.Integer.parseInt(Integer.java:527) org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:969) org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:902) org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75) org.springframework.validation.DataBinder.applyPropertyValues(DataBinder.java:740) org.springframework.validation.DataBinder.doBind(DataBinder.java:636) org.springframework.web.bind.WebDataBinder.doBind(WebDataBinder.java:191) org.springframework.web.bind.ServletRequestDataBinder.bind(ServletRequestDataBinder.java:112) org.springframework.web.servlet.mvc.method.annotation.ServletModelAttributeMethodProcessor.bindRequestParameters(ServletModelAttributeMethodProcessor.java:153) org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:106) org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:77) org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:162) org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:123) org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686) org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936) org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838) javax.servlet.http.HttpServlet.service(HttpServlet.java:647) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812) javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
I tried creating a custom data binder, but that didn't help.
Could anyone direct me to the right way to do these things? This is the first time I'm trying to make a web app by myself.
Here is the Agent class:
@Document(collection = "AgentCollection")
public class Agent
{
@Id
private String _id;
private String _name;
private String _type;
private ArrayList<String> _actionList;
private ArrayList<String> _attributeList;
private ArrayList<String> _behaviorTreeList;
private ArrayList<String> _itemList;
private ArrayList<String> _personalityTraitList;
private ArrayList<String> _skillList;
private ArrayList<String> _triggerList;
public String getId()
{
return _id;
}
public void setId(String id)
{
_id = id;
}
public String getName()
{
return _name;
}
public void setName(String name)
{
_name = name;
}
public String getType()
{
return _type;
}
public void setType(String type)
{
_type = type;
}
public ArrayList<String> getAttributeList()
{
return _attributeList;
}
public void setAttributeList(final ArrayList<String> attributeList)
{
_attributeList = attributeList;
}
public ArrayList<String> getPresonalityTraitList()
{
return _personalityTraitList;
}
public void setPersonalityTraitList(final ArrayList<String> personalityTraitList)
{
_personalityTraitList = personalityTraitList;
}
public ArrayList<String> getSkillList()
{
return _skillList;
}
public void setSkillList(final ArrayList<String> skillList)
{
_skillList = skillList;
}
public ArrayList<String> getActionList()
{
return _actionList;
}
public void setActionList(final ArrayList<String> actionList)
{
_actionList = actionList;
}
public ArrayList<String> getTriggerList()
{
return _triggerList;
}
public void setTriggerList(final ArrayList<String> triggerList)
{
_triggerList = triggerList;
}
public ArrayList<String> getItemList()
{
return _itemList;
}
public void setItemList(final ArrayList<String> itemList)
{
_itemList = itemList;
}
public ArrayList<String> getBehaviorTreeList()
{
return _behaviorTreeList;
}
public void setBehaviorTreeList(final ArrayList<String> behaviorTreeList)
{
_behaviorTreeList = behaviorTreeList;
}
}
Thanks, Matt
Upvotes: 2
Views: 8529
Reputation: 1795
Spring doesn't handle empty square bracket. To summarize you can use
but not
I created the ticket https://jira.springsource.org/browse/SPR-11214
Upvotes: 0