2

I have no idea where I've made a mistake. I've been trying to solve this problem for hours but can't figure it out... I'm getting HTTP Status 400 The request sent by the client was syntactically incorrect. while submiting the form with list of objects with some checkboxes to each of the objects. Heres some of the code:

Controller:

@RequestMapping(value = "/admin/panel", method = RequestMethod.GET)
public String adminPanel(Locale locale, Model model, Form form,
        HttpServletRequest request) {
    FormWrapper wrapper = getFormWrapper();
    model.addAttribute("listOfObjects", wrapper);
    model.addAttribute("allCategories", dao.getCatsList());
    return "WEB-INF/views/index/admin/home";
}


@RequestMapping(value = "/admin/saveAdmin", method = RequestMethod.POST)
public String save(Model model, @ModelAttribute(value="listOfObjects") FormWrapper listOfObjects) {
    return "redirect:../index.html"; 
}

JSP:

<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>

<form:form modelAttribute="listOfObjects" method="POST" action="/admin/saveAdmin">
  <c:forEach var="myObject" items="${listOfObjects.list}" varStatus="loop">

    <form:checkboxes items="${allCategories}" path="list[${loop.index}].selectedCategories" itemLabel="name"/>

  </c:forEach>
    <input type="submit" value="saveTest"/>
</form:form>

FormWrapper:

public class FormWrapper {
private List<Form> list;

public List<Form> getList() {
    return list;
}

public void setList(List<Form> list) {
    this.list = list;
}

}

Category:

 public class Category{
@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
 private Long categoryId;
 private String name;

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public Long getCategoryId() {
    return categoryId;
}

public void setCategoryId(Long categoryId) {
    this.categoryId = categoryId;
}
@Override
public boolean equals(Object obj) {
    if(obj instanceof Category){
        return getCategoryId().equals(((Category)obj).getCategoryId());
    } else {
        return false;
    }
}
}

Any help is appreciated. I tried to change the model attribute adnotatnion to RequestParam , but in such case , my object is always null

3
  • 2
    Need to see your FormWrapper definition
    – gerrytan
    Aug 18, 2014 at 1:25
  • What type does dao.getCatsList() give?
    – gerrytan
    Aug 18, 2014 at 23:34
  • List<Category> , I've updated question with implementation of Category
    – xwhyz
    Aug 25, 2014 at 20:22

2 Answers 2

1

Is it because, the FormWrapper class do not have a property "selectedCategories". I tried removing the "selectedCategories" Then the form was submitted successfully.

<form:checkboxes items="${allCategories}" path="list[${loop.index}]" itemLabel="name"/>
0

I'm not sure I understand your jsp correctly but this problem occurs when something in the jsp form does not match with the parameters you're handling at the controller.

Are you sure that "path" variable below is ok?

<form:checkboxes items="${allCategories}" path="list[${loop.index}].selectedCategories" itemLabel="name"/>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.