You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Vincent Lin <vi...@gmail.com> on 2007/06/11 04:44:31 UTC

[S2] datetimepicker reset value to 00:00 when type="time" after submitting page

I have a datetimepicker in my JSP to let user select time:

<s:datetimepicker name="searchBean.createTimeTmTo"
                   language="en_US" type="time" displayFormat="HH:mm" />

When user select 10:15 and submit to webserver, after the web page refreshes
the value becomes 00:00.
Is this another datetimepicker bug?

I have a type converter for converting time the format string is "HH:mm":

public class TimeConverter extends StrutsTypeConverter {

    private static Logger log = Logger.getLogger(TimeConverter.class);

    public Object convertFromString(Map context, String[] values,
        Class toClass) {
        log.debug("entering convertFromString() values[0]='" + values[0] +
"'");
        if (StringUtil.isEmpty(values[0])) {
            return null;
        }
        try {
            Date dt = TimeUtil.getGuiTimeFormat().parse(values[0]);
            Object rtn = new java.sql.Time(dt.getTime());
            log.debug("rtn=" + rtn);
            return rtn;
        } catch (Exception e) {
            log.error(e, e);
        }
        return null;
    }

    public String convertToString(Map context, Object o) {
        log.debug("entering convertToString() o=" + o);
        String str = null;
        if ( o != null ) {
            str = TimeUtil.getGuiTimeFormat().format(o);
            log.debug("entering convertToString() str=" + str);
        }
        return str;
    }
}

But the debug log shows the time str is 10:15.

Thanks!