I have a form with 3 select boxes (day, month & year). I need to bind these fields to a single Date field in my command object. What is the best practice for doing this?
I have a form with 3 select boxes (day, month & year). I need to bind these fields to a single Date field in my command object. What is the best practice for doing this?
You can make your own date form object with each field (day, month & year) as a nested property. This allows you to valid the fields individually or as a group.
Another option would be to combine them into a single string in Javascript, and submit that.
Or make use of the deprecated methods (shock horror) of the existing java.util.Date (get/SetDay|Month|Year).
i have this broblem and, if possible, i would like to see, please, some example of solution... i have the following:
the date is shown, like yyyy-mm-dd... without any problem, but when this field is modificated, the onSubmid method is not called because, i think, of some validation of spring, that cannot "translate" this new yyyy-mm-dd in Date again... can u plz help me with that?Code:<Spring:bind path="fxRate.rpDate"> <input type="text" name="rpDate" size="10" value="${status.value}" /> </Spring:bind>
thks a lot
Have you registered a property editor against your date field?
From AbstractClinicForm in the PetClinic example:if possible, i would like to see, please, some example of solution
Code:protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false)); binder.registerCustomEditor(String.class, new StringTrimmerEditor(false)); }
thks for replies!!
yes :oOriginally Posted by yatesco
not working :_-(Originally Posted by katentim
this one too..Code:public void initBinder(HttpServletRequest req,ServletRequestDataBinder binder) throws Exception{ SimpleDateFormat specFormat = new SimpleDateFormat("yyyy-MM-dd"); CustomDateEditor specEditor = new CustomDateEditor(specFormat, true); binder.registerCustomEditor(Date.class, "rpDate", specEditor); }
may be is there a problem with java.sql.Date class? do i need to use java.util.Date ??
when i just do not show this field (it is pre-setted earlier in formBackingObject() method), all works perfecly! (but SOMETIMES this pre-setted date needs to be modified)
plz help :o my chef is starting to look eagly at me about this problem... thks again!
Last edited by orusso; Jun 28th, 2006 at 05:11 AM.
Yes. CustomDateEditor is a property editor for java.util.Date.do i need to use java.util.Date ?
but all java.sql.Date is java.util.Date... why it was not working?Originally Posted by katentim
( now it is :-D, i have modified the field extencion in POJO )
but now on ViewAll page, the date appear like "2006-06-28 00:00:00.0" .... with java.sql.Date it was "2006-06-28", a little bit more user-view-friendly... there is no initBinder() for the normal Controller interface (my viewAll-controller implements Controller)... do u plz have any suggestion for me? thks
Last edited by orusso; Jun 30th, 2006 at 05:43 AM.