Hello,

I'm trying to get some date formatting on the go for Date.class field. The 
SimpleConverterAdapter example that was posted to the list works fine for 
URLs ( http://sourceforge.net/mailarchive/message.php?msg_id=15132297 ). But 
after rewriting it for doing date formatting I just get an exception when the 
value is being written back to my domain POJO with the help of a 
CompoundPropertyModel.

Anyone know what is going on?

code:
-----------------------------
TextField dob = new TextField("dateOfBirth",Date.class) {
  private SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
  public IConverter getConverter() {
    return new SimpleConverterAdapter() {

      public String toString(Object value) {
        System.err.println("SimpleConverterAdapter.toString() "+value);
          return value != null ? df.format( (Date)value ) : null;
      }

      public Object toObject(String value) {
        System.err.println("TextField.toObject() "+value);
        if(value==null || "".equals(value)) {
          throw new ConversionException("'"+value+"' is not a valid date.");
        }
        Date newDate = df.parse(value,new ParsePosition(0));
        System.err.println("TextField.toObject() returning "+newDate);
        return newDate;
      }
    };
  }
};
-----------------------------
exception (slightly formatted, 1-2-2003 was submitted in the HTML text field):

-----------------------------
INFO  - MarkupCache                - Loading markup from 
file:/home/sbe/devel/apache-tomcat-5.5.16/webapps/wicket-examples/WEB-INF/classes/wicket/examples/tvguide/PersonsTab.html

INFO  - MarkupCache                - Loading markup from 
jar:file:/home/sbe/devel/apache-tomcat-5.5.16/webapps/wicket-examples/WEB-INF/lib/wicket-1.2-beta2.jar!/wicket/markup/html/panel/FeedbackPanel.html

SimpleConverterAdapter.toString(): 'Sat Apr 01 10:39:55 CEST 2006'

SimpleConverterAdapter.toObject(): '01-02-2003'

SimpleConverterAdapter.toObject() returning 'Sat Feb 01 00:00:00 CET 2003'

SimpleConverterAdapter.toObject(): 'Sat Feb 01 00:00:00 CET 2003'               
                                                                           

SimpleConverterAdapter.toObject() returning 'null'

ERROR - RequestCycle               - Method onFormSubmitted of interface 
wicket.markup.html.form.IFormSubmitListener targeted at component 
[MarkupContainer [Component id = personform, page = 
wicket.examples.tvguide.TvGuidePage, path = 
1:tabs:panel:personform.PersonsTab$4, isVisible = true, isVersioned = true]] 
threw an exception

wicket.WicketRuntimeException: Method onFormSubmitted of interface 
wicket.markup.html.form.IFormSubmitListener targeted at component 
[MarkupContainer [Component id = personform, page = 
wicket.examples.tvguide.TvGuidePage, path = 
1:tabs:panel:personform.PersonsTab$4, isVisible = true, isVersioned = true]] 
threw an exception
  at wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:173)
  at 
wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:74)
  at 
wicket.request.compound.DefaultEventProcessorStrategy.processEvents(DefaultEventProcessorStrategy.java:65)
...

Caused by: java.lang.reflect.InvocationTargetException
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  ...

Caused by: wicket.util.convert.ConversionException: Can't convert value: Sat 
Feb 01 00:00:00 CET 2003 to class: class java.util.Date for setting it on 
[EMAIL PROTECTED]
        at 
wicket.util.lang.PropertyResolver$MethodGetAndSet.setValue(PropertyResolver.java:824)
  ...

INFO  - MarkupCache                - Loading markup from 
jar:file:/home/sbe/devel/apache-tomcat-5.5.16/webapps/wicket-examples/WEB-INF/lib/wicket-1.2-beta2.jar!/wicket/markup/html/pages/ExceptionErrorPage.html

SimpleConverterAdapter.toString(): 'Sat Apr 01 10:39:55 CEST 2006'

-----------------------------

info:

* wicket 1.2 beta 2
* tomcat 5.5
* jdk 1.5.0_06

thank you,

-- 
Simon Edwards             | KDE-NL, Guidance tools, Guarddog Firewall
[EMAIL PROTECTED]       | http://www.simonzone.com/software/
Nijmegen, The Netherlands | "ZooTV? You made the right choice."


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to