How to use DateTimeField with java.sql.Timestamp

2009-12-17 Thread chinedu efoagui
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 codetimein/code property.
*
*/
   @Column(name = timein  )
   public java.sql.Timestamp getTimein() {
  return timein;
   }

   /**
* Sets the value of the codetimein/code property.
*
* @param timein the value for the codetimein/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: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: How to use DateTimeField with java.sql.Timestamp

2009-12-17 Thread Matthias Keller
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 codetimein/code property.
*
*/
   @Column(name = timein  )
   public java.sql.Timestamp getTimein() {
  return timein;
   }

   /**
* Sets the value of the codetimein/code property.
*
* @param timein the value for the codetimein/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: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

  



--
matthias.kel...@ergon.ch  +41 44 268 83 98
Ergon Informatik AG, Kleinstrasse 15, CH-8008 Zürich
http://www.ergon.ch
__
e r g o nsmart people - smart software




smime.p7s
Description: S/MIME Cryptographic Signature


Re: How to use DateTimeField with java.sql.Timestamp

2009-12-17 Thread Marc Nuri (GMail)
You can create a custom converter.

A simpler quick solution is to create two methods to encapsulate the sql
date in a normal date:
The pojo object accepts a java.sql.Timestamp

Your original methods:
[CODE]
  @Column(name = timein  )
  public java.sql.Timestamp getTimein() {
 return timein;
  }

  public void setTimein(java.sql.Timestamp timein) {
 this.timein = timein;
  }

//Add these too:
public java.util.Date getTimeinDate(){
return new java.utilDate(getTimein().getTime());
}
public void setTimeinDate(java.util.Date timeinDate){
setTimein(new java.sql.Timestamp(timeinDate.getTime());
}
[/CODE]

Now you can simply bind to timeinDate and you will get your Timestamp as a
Date.
Hope it helps
--
Marc Nuri


Re: How to use DateTimeField with java.sql.Timestamp

2009-12-17 Thread chinedu efoagui
hello @matt

I carried out your instruction i still got the same error

WicketMessage: Error calling method: public void
org.apache.wicket.extensions.yui.calendar.DateTimeField.setDate(java.util.Date)
on object: [MarkupContainer [Component id = timein]]

Root cause:

java.lang.IllegalArgumentException: argument type mismatch
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at java.lang.reflect.Method.invoke(Method.java:597)

I subclassed the Datetimefield

public class MwDateTimeField extends DateTimeField
{

public MwDateTimeField(String id){

super(id);
//setType(Timestamp.class);

}

@Override
protected DateTextField newDateTextField(String id, PropertyModel
dateFieldModel)
  {
  return new DateTextField(id, dateFieldModel,new
StyleTimeStampConverter(false));
  }
}


and the StyleDateConverter

public class StyleTimeStampConverter extends StyleDateConverter {


public StyleTimeStampConverter(boolean id){

super(id);


}

@Override
public Timestamp convertToObject(String value, Locale locale) {
Date zatime=super.convertToObject(value, locale);

java.sql.Timestamp timeStampDate = new
Timestamp(zatime.getTime());
return timeStampDate;
}


what seems to be the problem.



On Thu, Dec 17, 2009 at 2:50 PM, Matthias Keller
matthias.kel...@ergon.ch wrote:
 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 codetimein/code property.
    *
    */
   @Column(name = timein  )
   public java.sql.Timestamp getTimein() {
      return timein;
   }

   /**
    * Sets the value of the codetimein/code property.
    *
    * @param timein the value for the codetimein/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
 

Re: How to use DateTimeField with java.sql.Timestamp

2009-12-17 Thread chinedu efoagui
thanks a lot
I resolved it by add those getter and setters

I would consider that a hack anyway but there still needs to be a
simpler more streamlined way of achieving the same thing using the
converters.
Thanks again.

On Thu, Dec 17, 2009 at 3:32 PM, chinedu efoagui chinedub...@gmail.com wrote:
 hello @matt

 I carried out your instruction i still got the same error

 WicketMessage: Error calling method: public void
 org.apache.wicket.extensions.yui.calendar.DateTimeField.setDate(java.util.Date)
 on object: [MarkupContainer [Component id = timein]]

 Root cause:

 java.lang.IllegalArgumentException: argument type mismatch
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at 
 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     at java.lang.reflect.Method.invoke(Method.java:597)

 I subclassed the Datetimefield

 public class MwDateTimeField extends DateTimeField
 {

    public MwDateTimeField(String id){

        super(id);
        //setType(Timestamp.class);

    }

   �...@override
    protected DateTextField newDateTextField(String id, PropertyModel
 dateFieldModel)
  {
      return new DateTextField(id, dateFieldModel,new
 StyleTimeStampConverter(false));
  }
 }


 and the StyleDateConverter

 public class StyleTimeStampConverter extends StyleDateConverter {


        public StyleTimeStampConverter(boolean id){

            super(id);


        }

   �...@override
    public Timestamp convertToObject(String value, Locale locale) {
        Date zatime=super.convertToObject(value, locale);

        java.sql.Timestamp timeStampDate = new
 Timestamp(zatime.getTime());
        return timeStampDate;
    }


 what seems to be the problem.



 On Thu, Dec 17, 2009 at 2:50 PM, Matthias Keller
 matthias.kel...@ergon.ch wrote:
 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 codetimein/code property.
    *
    */
   @Column(name = timein  )
   public java.sql.Timestamp getTimein() {
      return timein;
   }

   /**
    * Sets the value of the codetimein/code property.
    *
    * @param timein the value for the codetimein/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
 

Re: How to use DateTimeField with java.sql.Timestamp

2009-12-17 Thread Marc Nuri (GMail)
I use that continuously. Not only in Wicket but with swing too. It's a kind
of hack but it does its job.
The economic way is to use a converter because in the future you may use the
converter with other model classes. In the other hand if you use the same
model with different technologies (Swing, wicket, reporting...) then you can
always bind a field to known data type.
I use this too when I need to combine two fields in one. If you have a
Person class and name and surname fields, you can add a getter method to
read name+surname and bind that in a read only field or a report.
Cheers.
--
Marc Nuri