DateTimeField internally uses a DateTextField which is a normal TextField initialized as type java.util.Date

You could create a class:

public class TimestampField extends DateTimeField {
protected DateTextField newDateTextField(String id, PropertyModel dateFieldModel)
   {
return new DateTextField(id, dateFieldModel, new StyleTimestampConverter(false));
   }
}

This allows you to create your own converter which results in a Timestamp object. you could for example just extend StyleDateConverter to take advantage of its implementation and in your override of convertToObject() you could convert the super.convertToObject() Date to Timestamp

Matt

chinedu efoagui wrote:
Hello,
I am very new to Wicket
I am building an application that requires a Datetimefield

The field in my database 'timein' is datetime.

The pojo object accepts a java.sql.Timestamp
  /**
    * Returns the value of the <code>timein</code> property.
    *
    */
   @Column(name = "timein"  )
   public java.sql.Timestamp getTimein() {
      return timein;
   }

   /**
    * Sets the value of the <code>timein</code> property.
    *
    * @param timein the value for the <code>timein</code> property
    */
   public void setTimein(java.sql.Timestamp timein) {
      this.timein = timein;
   }
but the DateTimefield uses java.util.get

when i save the form to the database i get this error below

org.apache.wicket.WicketRuntimeException: Error calling method: public
void 
org.apache.wicket.extensions.yui.calendar.DateTimeField.setDate(java.util.Date)
on object: [MarkupContainer [Component id = timein]]
        at 
org.apache.wicket.util.lang.PropertyResolver$MethodGetAndSet.setValue(PropertyResolver.java:1133)
        at 
org.apache.wicket.util.lang.PropertyResolver$ObjectAndGetSetter.setValue(PropertyResolver.java:588)
        at 
org.apache.wicket.util.lang.PropertyResolver.setValue(PropertyResolver.java:136)
        at 
org.apache.wicket.model.AbstractPropertyModel.setObject(AbstractPropertyModel.java:169)
        at 
org.apache.wicket.Component.setDefaultModelObject(Component.java:3052)
        at 
org.apache.wicket.markup.html.form.FormComponent.updateModel(FormComponent.java:1168)
        at 
org.apache.wicket.markup.html.form.Form$FormModelUpdateVisitor.component(Form.java:225)
        at 
org.apache.wicket.markup.html.form.FormComponent.visitComponentsPostOrderHelper(FormComponent.java:514)
        at 
org.apache.wicket.markup.html.form.FormComponent.visitComponentsPostOrderHelper(FormComponent.java:493)
        at 
org.apache.wicket.markup.html.form.FormComponent.visitComponentsPostOrderHelper(FormComponent.java:493)
Caused by: org.apache.wicket.WicketRuntimeException: Error calling
method: public void
com.mw.hr.entity.personnelrecordsattendance.PersonnelrecordsAttendance.setTimein(java.sql.Timestamp)
on object: 
com.mw.hr.entity.personnelrecordsattendance.personnelrecordsattenda...@1f0c408
        at 
org.apache.wicket.util.lang.PropertyResolver$MethodGetAndSet.setValue(PropertyResolver.java:1138)
        at 
org.apache.wicket.util.lang.PropertyResolver$ObjectAndGetSetter.setValue(PropertyResolver.java:588)
        at 
org.apache.wicket.util.lang.PropertyResolver.setValue(PropertyResolver.java:136)
        at 
org.apache.wicket.model.AbstractPropertyModel.setObject(AbstractPropertyModel.java:169)
        at 
org.apache.wicket.Component.setDefaultModelObject(Component.java:3052)
        at 
org.apache.wicket.extensions.yui.calendar.DateTimeField.setDate(DateTimeField.java:239)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
Caused by: java.lang.IllegalArgumentException: argument type mismatch
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at 
org.apache.wicket.util.lang.PropertyResolver$MethodGetAndSet.setValue(PropertyResolver.java:1129)
        ... 51 more

please can i get an idea or sample code to convert the input from the
datetimefiled to java.sql.timestamp??

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



--
[email protected]  +41 44 268 83 98
Ergon Informatik AG, Kleinstrasse 15, CH-8008 Zürich
http://www.ergon.ch
______________________________________________________________
e r g o n    smart people - smart software


Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to