Thanks Michael, i'll have a go at that and post again if i need further assistance.

Philip

Michael Horwitz wrote:
Hi Philip,

On 3/1/07, *Philip Barlow* <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>> wrote:

    Hi,

    I recently set up Appfuse 2.0M3 on my machine at home so i could play
    around with it a bit. Coming from a Struts background i decided to
    try
    out Spring MVC and so i downloaded and ran the Spring MVC Basic
    package.
    All is working fine after following the excellent quickstart guide on
    the appfuse site.

    One problem i encountered when trying to develop the application
    further
    was how to handle date inputs. I  have had problems with this in
    Struts
    before and ended up writing a conversion class to convert Dates in
    String format to java.util.Date objects. I don't know if this is the
    right approach to take and i would like to get opinions on this.

    Basically what i am looking for is help on the best approaches for the
    following:
    1. Adding a date to a html form. (Previously i used a javaScript
    calendar which worked fine)

Sounds about right. There are several options, the most popular seems to be jscalendar: http://jscalendar.sf.net.

    2. Validating the date using Commons Validator (validation.xml)

Dependends exactly what you want to validate. Required field or just the format? Commons validator more than likely already has something built in here.

    3. Should the date be String or Date when it reaches the Controller
(Hope i'm using the correct term!) Spring MVC should bind the date into the relevant field on the command object for you. You will need to set up the binder on the controller which involves overriding the initBinder() method (change the format as appropriate, the registerCustomEditor method also accepts an optional second parameter which limits the editor to a specific property): protected void initBinder(HttpServletRequest httpServletRequest, ServletRequestDataBinder servletRequestDataBinder)
{
  super.initBinder(httpServletRequest, servletRequestDataBinder);
servletRequestDataBinder.registerCustomEditor (Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"),true));
}
Mike.

    4. Any resources, links or examples of the above.

    Thanks in advance

    Philip

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: [EMAIL PROTECTED]
    <mailto:[EMAIL PROTECTED]>
    For additional commands, e-mail: [EMAIL PROTECTED]
    <mailto:[EMAIL PROTECTED]>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to