A Bug in SqlDateConverter?

2009-02-22 Thread rolandpeng

Now I use wicket 1.3.5.

There is a date field in my webpage.and it is not required.
The date class type is java.sql.date

But I alway have a NullPointerException while the input of this optional
field is empty.
the exceptions below:
Caused by: java.lang.NullPointerException
at
org.apache.wicket.util.convert.converters.SqlDateConverter.convertToObject(SqlDateConverter.java:35)
at
org.apache.wicket.markup.html.form.FormComponent.convertInput(FormComponent.java:1211)
...

How do I fix this problem?
Now I must set a date into my date filed  to pass the program.But this field
is not required.
Thanks.
-- 
View this message in context: 
http://www.nabble.com/A-Bug-in-SqlDateConverter--tp22145097p22145097.html
Sent from the Wicket - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: A Bug in SqlDateConverter?

2009-02-22 Thread Martin Makundi
I recommend porting to 1.4-rc2 already ;)

Alternatively you can override / patch the SqlDateConverter with a new class:

package org.apache.wicket.util.convert.converters;

public class SqlDateConverter extends AbstractConverter
{
  private static final long serialVersionUID = 1L;

  /**
   * @see 
org.apache.wicket.util.convert.IConverter#convertToObject(java.lang.String,Locale)
   */
  public Date convertToObject(final String value, Locale locale)
  {
if (value == null || Strings.isEmpty(value))
{
  return null;
}
else
{
  return new Date(((java.util.Date)parse(getDateFormat(locale),
value, locale)).getTime());
}
  }

  /**
   * @see 
org.apache.wicket.util.convert.converters.DateConverter#convertToObject(java.lang.String,
   *  java.util.Locale)
   */
  @Override
  public String convertToString(Object value, Locale locale)
  {
final DateFormat dateFormat = getDateFormat(locale);
if (dateFormat != null)
{
  return dateFormat.format(value);
}
return value.toString();
  }


  /**
   * @param locale
   * @return Returns the date format.
   */
  public DateFormat getDateFormat(Locale locale)
  {
if (locale == null)
{
  locale = Locale.getDefault();
}

return DateFormat.getDateInstance(DateFormat.SHORT, locale);
  }

  @Override
  protected ClassDate getTargetType()
  {
return Date.class;
  }
}


2009/2/22 rolandpeng rolandp...@cht.com.tw:

 Now I use wicket 1.3.5.

 There is a date field in my webpage.and it is not required.
 The date class type is java.sql.date

 But I alway have a NullPointerException while the input of this optional
 field is empty.
 the exceptions below:
 Caused by: java.lang.NullPointerException
at
 org.apache.wicket.util.convert.converters.SqlDateConverter.convertToObject(SqlDateConverter.java:35)
at
 org.apache.wicket.markup.html.form.FormComponent.convertInput(FormComponent.java:1211)
 ...

 How do I fix this problem?
 Now I must set a date into my date filed  to pass the program.But this field
 is not required.
 Thanks.
 --
 View this message in context: 
 http://www.nabble.com/A-Bug-in-SqlDateConverter--tp22145097p22145097.html
 Sent from the Wicket - User mailing list archive at Nabble.com.


 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org



-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: A Bug in SqlDateConverter?

2009-02-22 Thread rolandpeng

Thanks for your quick response.

Now I have updated my lib into wicket1.4-rc2.

Rerun the date input functoin and I have another exception.(the date field
is not empty)

--
Caused by: java.lang.ClassCastException: java.util.Date
at
org.apache.wicket.util.convert.converters.SqlDateConverter.convertToObject(SqlDateConverter.java:43)
at
org.apache.wicket.util.convert.converters.SqlDateConverter.convertToObject(SqlDateConverter.java:28)
at
org.apache.wicket.markup.html.form.FormComponent.convertInput(FormComponent.java:1297)
--

Is this also another bug of SqlDateConverter?
Or I need to modify any code of my program?
Thank you.
-- 
View this message in context: 
http://www.nabble.com/A-Bug-in-SqlDateConverter--tp22145097p22145456.html
Sent from the Wicket - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: A Bug in SqlDateConverter?

2009-02-22 Thread Martin Makundi
In my opinnion yes. Try the snipplet I sent you. If it does not work,
I will have another look.

**
Martin

2009/2/22 rolandpeng rolandp...@cht.com.tw:

 Thanks for your quick response.

 Now I have updated my lib into wicket1.4-rc2.

 Rerun the date input functoin and I have another exception.(the date field
 is not empty)

 --
 Caused by: java.lang.ClassCastException: java.util.Date
at
 org.apache.wicket.util.convert.converters.SqlDateConverter.convertToObject(SqlDateConverter.java:43)
at
 org.apache.wicket.util.convert.converters.SqlDateConverter.convertToObject(SqlDateConverter.java:28)
at
 org.apache.wicket.markup.html.form.FormComponent.convertInput(FormComponent.java:1297)
 --

 Is this also another bug of SqlDateConverter?
 Or I need to modify any code of my program?
 Thank you.
 --
 View this message in context: 
 http://www.nabble.com/A-Bug-in-SqlDateConverter--tp22145097p22145456.html
 Sent from the Wicket - User mailing list archive at Nabble.com.


 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org



-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: A Bug in SqlDateConverter?

2009-02-22 Thread Martin Makundi
Note, that the SqlDateConverter -class must use java.sql.Date when it
returns the value. (that's why it is called 'SqlDateConverter')

**
Martin

2009/2/22 Martin Makundi martin.maku...@koodaripalvelut.com:
 In my opinnion yes. Try the snipplet I sent you. If it does not work,
 I will have another look.

 **
 Martin

 2009/2/22 rolandpeng rolandp...@cht.com.tw:

 Thanks for your quick response.

 Now I have updated my lib into wicket1.4-rc2.

 Rerun the date input functoin and I have another exception.(the date field
 is not empty)

 --
 Caused by: java.lang.ClassCastException: java.util.Date
at
 org.apache.wicket.util.convert.converters.SqlDateConverter.convertToObject(SqlDateConverter.java:43)
at
 org.apache.wicket.util.convert.converters.SqlDateConverter.convertToObject(SqlDateConverter.java:28)
at
 org.apache.wicket.markup.html.form.FormComponent.convertInput(FormComponent.java:1297)
 --

 Is this also another bug of SqlDateConverter?
 Or I need to modify any code of my program?
 Thank you.
 --
 View this message in context: 
 http://www.nabble.com/A-Bug-in-SqlDateConverter--tp22145097p22145456.html
 Sent from the Wicket - User mailing list archive at Nabble.com.


 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org




-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: A Bug in SqlDateConverter?

2009-02-22 Thread Igor Vaynberg
If input is null and the field is not required converters do not run.
Show us your code.

-Igor

On 2/22/09, rolandpeng rolandp...@cht.com.tw wrote:

 Now I use wicket 1.3.5.

 There is a date field in my webpage.and it is not required.
 The date class type is java.sql.date

 But I alway have a NullPointerException while the input of this optional
 field is empty.
 the exceptions below:
 Caused by: java.lang.NullPointerException
   at
 org.apache.wicket.util.convert.converters.SqlDateConverter.convertToObject(SqlDateConverter.java:35)
   at
 org.apache.wicket.markup.html.form.FormComponent.convertInput(FormComponent.java:1211)
 ...

 How do I fix this problem?
 Now I must set a date into my date filed  to pass the program.But this field
 is not required.
 Thanks.
 --
 View this message in context:
 http://www.nabble.com/A-Bug-in-SqlDateConverter--tp22145097p22145097.html
 Sent from the Wicket - User mailing list archive at Nabble.com.


 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org



-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: A Bug in SqlDateConverter?

2009-02-22 Thread rolandpeng

Here you are. 
html and java files are both uploaded as attachments for your reference.
Data type of the date field in my entity is also java.sql.Date.

By the way,instead of above method,
Now I have a try to change all the date type of Date from java.sql.Date into
java.util.Date.
Then everything is fine.

--

If input is null and the field is not required converters do not run.
Show us your code.

-Igor

http://www.nabble.com/file/p22155201/Bulletin.java Bulletin.java 
http://www.nabble.com/file/p22155201/ModifyBulletin.java ModifyBulletin.java 
http://www.nabble.com/file/p22155201/ModifyBulletin.html ModifyBulletin.html 
-- 
View this message in context: 
http://www.nabble.com/A-Bug-in-SqlDateConverter--tp22145097p22155201.html
Sent from the Wicket - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: A Bug in SqlDateConverter?

2009-02-22 Thread Igor Vaynberg
does the error go away if you do not add the datepickers?

-igor

On Sun, Feb 22, 2009 at 8:08 PM, rolandpeng rolandp...@cht.com.tw wrote:

 Here you are.
 html and java files are both uploaded as attachments for your reference.
 Data type of the date field in my entity is also java.sql.Date.

 By the way,instead of above method,
 Now I have a try to change all the date type of Date from java.sql.Date into
 java.util.Date.
 Then everything is fine.

 --

 If input is null and the field is not required converters do not run.
 Show us your code.

 -Igor

 http://www.nabble.com/file/p22155201/Bulletin.java Bulletin.java
 http://www.nabble.com/file/p22155201/ModifyBulletin.java ModifyBulletin.java
 http://www.nabble.com/file/p22155201/ModifyBulletin.html ModifyBulletin.html
 --
 View this message in context: 
 http://www.nabble.com/A-Bug-in-SqlDateConverter--tp22145097p22155201.html
 Sent from the Wicket - User mailing list archive at Nabble.com.


 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org



-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: A Bug in SqlDateConverter?

2009-02-22 Thread rolandpeng

igor, I'm not sure if the datepickers removed will make the error go away.

Since all of my programs have been refactorred from java.sql.Date to
java.util.Date,I can't try your assumption in my application now.

Anyway,now I adopt java.util.Date instead of java.sql.Date,and everything
goes well.
Thanks.

roland.
--

does the error go away if you do not add the datepickers?

-igor


-- 
View this message in context: 
http://www.nabble.com/A-Bug-in-SqlDateConverter--tp22145097p22156014.html
Sent from the Wicket - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org