reset password
Author Message
poonam31
Posts: 35
Posted 14:29 Aug 11, 2015 |

Hello,

On create job form, I have taken dates as string input and in controller i am defining them using required=false attribute.

( for ex - @RequestParam(required=false) String publishDate ) and then converting them to date format. This is working fine if I enter value on form when run but if i keep the field blank then it gives me a error.  

The request sent by the client was syntactically incorrect.

publish date and close date can be null, so i want my form to allow null values. 

Could anyone help with this?

Also, for select tag I am taking values as userid and then  in controller using that id , i want to get the user object and so on.

But I get the above same error.

 

 

 

 

 

cysun
Posts: 2935
Posted 14:42 Aug 11, 2015 |

You probably have something like <form:input path="publishDate"> in your JSP and the error was caused by Spring trying to bind a date property to a string field. Just change the tag to a regular HTML <input> tag and it should solve the date problem.

The problem with the dropdown list and the checkboxes are the same.

To make the binding work you need to use Property Editor that converts between string and object. See this and my Week 6 email.

poonam31
Posts: 35
Posted 14:48 Aug 11, 2015 |

No. fields for date on form are regular input tags.

<input type="text" name="publishDate"  />             ------------ same for close date

i am converting these strings to dates in controller and then setting them to job object.

When I enter values , it works fine. but the issue is when I keep the fields blank.

cysun
Posts: 2935
Posted 14:52 Aug 11, 2015 |
poonam31 wrote:

No. fields for date on form are regular input tags.

<input type="text" name="publishDate"  />             ------------ same for close date

i am converting these strings to dates in controller and then setting them to job object.

When I enter values , it works fine. but the issue is when I keep the fields blank.

OK, I see. Although it's not a spring <form> tag, Spring will try to set the property anyway because the field name matches the property name. Just change the field name to something like pdate and it should work (of course, also change the controller method argument accordingly).

poonam31
Posts: 35
Posted 14:57 Aug 11, 2015 |

Ohh okay. Now I got it. Thank you Professor.