Question

I'm using Spring 3.1.1.RELEASE. I have a model with the following attribute

@DateTimeFormat(pattern = "h:mm:ss a")
private java.util.Date meetingTime;

On my JSP, I have

                        <form:select path="meetingTime">
                            <form:option value="8:00 AM" name="8:00 AM" />
                        </form:select>

However, whenever I access my JSP I get the following error. Any ideas why its having trouble with the "AM/PM" portion of the time?

java.lang.IllegalArgumentException: Invalid format: "8:00 AM" is malformed at " AM"
    org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:683)
    org.springframework.format.datetime.joda.DateTimeParser.parse(DateTimeParser.java:46)
    org.springframework.format.datetime.joda.DateTimeParser.parse(DateTimeParser.java:1)
    org.springframework.format.support.FormattingConversionService$ParserConverter.convert(FormattingConversionService.java:173)
    org.springframework.format.support.FormattingConversionService$AnnotationParserConverter.convert(FormattingConversionService.java:265)
    org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:35)
    org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:171)
    org.springframework.core.convert.support.ConvertingPropertyEditorAdapter.setAsText(ConvertingPropertyEditorAdapter.java:59)
    org.springframework.web.servlet.tags.form.SelectedValueComparator.exhaustiveCompare(SelectedValueComparator.java:189)
    org.springframework.web.servlet.tags.form.SelectedValueComparator.isSelected(SelectedValueComparator.java:103)
    org.springframework.web.servlet.tags.form.OptionTag.isSelected(OptionTag.java:248)
    org.springframework.web.servlet.tags.form.OptionTag.renderOption(OptionTag.java:212)
    org.springframework.web.servlet.tags.form.OptionTag.renderDefaultContent(OptionTag.java:154)
    org.springframework.web.servlet.tags.form.AbstractHtmlElementBodyTag.doEndTag(AbstractHtmlElementBodyTag.java:69)
    org.apache.jsp.WEB_002dINF.views.class_.add_jsp$Helper.invoke0(add_jsp.java:779)
    org.apache.jsp.WEB_002dINF.views.class_.add_jsp$Helper.invoke(add_jsp.java:868)
    org.apache.jsp.tag.web.simplePage_tag.doTag(simplePage_tag.java:205)
    org.apache.jsp.WEB_002dINF.views.class_.add_jsp._jspService(add_jsp.java:123)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:326)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:253)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
    org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:262)
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1180)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:950)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:322)
    org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:116)
    org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:182)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:184)
    org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:155)
    org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
Was it helpful?

Solution

Try to use attribute "label": http://static.springsource.org/spring/docs/2.0.x/reference/spring-form.tld.html#spring-form.tld.option And note that you have time format: @DateTimeFormat(pattern = "h:mm:ss a") so use "8:00:00 AM" instead of "8:00 AM":

<form:select path="meetingTime">
   <form:option value="8:00:00 AM" label="8:00 AM" />
</form:select>

OTHER TIPS

Try this:

                     <form:select path="meetingTime">
                        <form:option value="8:00 AM">8:00 AM</form:option>
                     </form:select>

"8:00 AM" is not the name of the option; it is the value and the text you wish to display.

Also, I believe the format specification for "8:00 a" is "h:mm a", not "h:mm:ss a".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top