1

I have problem with simple MVC application.

dayoff.html
<div id="dayoff_operations" class="big_box_1">
    <form:form modelAttribute="dayOff" enctype="multipart/form-data" action="/dayoff.html" >
        <div style="width: 50%; float: left; margin-top: 0px ">
            <form:label path="forDate" ><spring:message code="dayoff.fordate.label"/></form:label>
            <form:input path="ax_forDate" id="datepicker" style="width:65px" readonly="readonly"/>&nbsp;&nbsp;
        </div>
        <div style="width: 50%; float: right; margin-top: 0px ">
            <form:label path="toDate" ><spring:message code="dayoff.todate.label"/></form:label>
            <form:input path="ax_toDate" id="datepicker2" style="width:65px" readonly="readonly" />&nbsp;&nbsp;
        </div>
        <div style="float: left">
            <form:select cssClass="more" path="dayofftype" items="${dayoffTypes.list}" itemLabel="label" itemValue="value" htmlEscape="false" cssErrorClass="errorsField"/>
            <form:errors path="dayofftype" cssClass="errors"/>
        </div>
        <input type="submit" name="add" value="Add"/>
    </form:form>

Here is my controller:

@Controller
@RequestMapping("/dayoff")
@SessionAttributes(types = {DayOff.class})
public class DaysOffController {
private Validator validator;
@Autowired
private ReloadableResourceBundleMessageSource messages;

@ModelAttribute("dayoffTypes")
public Map<String, Object> populateDayoffTypes(Locale locale) {
    return Utils.createComboMap(DayoffType.values(), messages, locale);
}

@RequestMapping(method = RequestMethod.GET)
public String setupForm(Model model) {      
    model.addAttribute("dayOff", new DayOff());
    model.addAttribute("cur_period",SessionManager.getCurrentPeriod());
    return "dayoff";
}

@RequestMapping(method = RequestMethod.POST, params = "add")
public String addNewHoliday(@ModelAttribute DayOff dayOff, BindingResult result, ModelMap model) {
    System.out.println("AAA");
    return "/dayoff";
}

When I click Add button Error 400: SRVE0295E: Error reported: 400 appears, there is no information at server console. I assume it is realted to the setupForm() method which is displaying the form and crushing it to future submits. Can you please guide me with this?

opad
  • 11
  • 1
  • 1
  • 3
  • Is your action of `/dayoff.html` correct? Are you mapping `*.html` to your controller methods? You probably also want to use `method="post"` to make sure you hit your correct controller method. – Beau Grantham May 15 '13 at 16:42
  • Can [this](http://stackoverflow.com/questions/1483063/spring-mvc-3-and-handling-static-content-am-i-missing-something) help !!! – AllTooSir May 15 '13 at 16:44
  • Yes, my DispatcherServlet maps `*.html` files. And `method="post"` is not required since in my html source file form is already declared as using `method="post"`. – opad May 15 '13 at 16:59
  • After few server restarts my code begin to work. Nothing really changed. Input triggering post action is declared: ``, controller configuration is: `@Controller @RequestMapping("/dayoff") @SessionAttributes(types = {DayOff.class}) public class DaysOffController {...}` and method responding to action POST with name `add` is declared as: `@RequestMapping(method = RequestMethod.POST, params = "add") public String addNewHoliday(@ModelAttribute DayOff dayOff, BindingResult result, ModelMap model) {..}` – opad May 17 '13 at 08:41

2 Answers2

5

Error 400: SRVE0295E occurs also when MVC cannot fill @ModelAttribute Form with values from HTML form.

For example:

  • class Form has primitive attribute int someCount
  • your HTML form has <input> to assign value to this primitive attribute
  • user entered empty value (null) to this <input>

You should not use primitive types such as int, boolean, float and so on.

lu_ko
  • 4,055
  • 2
  • 26
  • 31
  • 1
    I had a similar error because I was sending RequestParam that was not valid. Failed in IE but not in Chrome. – MattC Jul 29 '14 at 16:09
0

The return statements from setupForm and addNewHoliday are different. I presume you want to return the same view name from both. As you can see the form in order to submit it, I assume that the addNewHoliday return value of "/dayoff" should in fact be "dayoff"

Mark Chorley
  • 2,087
  • 2
  • 22
  • 29