try this ..
public Object convert(Object value, Class c) {
//If the value is already of the same type as 'c'
//then return it
if (c== value.getClass()){
return value;
}
On 4/27/07, kubino <[EMAIL PROTECTED]> wrote:
Hi Johan, I tried this
TextField dateFrom = new TextField("dateFrom",new
PropertyModel(filtr,"dateFrom")) {
public IConverter getConverter() {
return new IConverter() {
public Object convert(Object value, Class c) {
try
{
if(c == String.class)
{
return new
SimpleDateFormat("dd-MM-yyyy").format((Date)value);
}
else
return new
SimpleDateFormat("dd-MM-yyyy").parse((String)value);
}
catch(ParseException pex)
{
return null;
}
}
public Locale getLocale() {
return getLocale();
}
public void setLocale(Locale locale) {
}
};
}};
filtr is instance of class where is property
Date dateFrom with apropriate getter and setter. I always get this
exception
when I try fill and post the field.
icketMessage: unable to set object 11.05.2000, model:
Model:classname=[wicket.model.PropertyModel]:attached=true:nestedModel=[
[EMAIL PROTECTED]
]:expression=[dateFrom]:propertyType=[null],
called with component [MarkupContainer [Component id = dateFrom, page =
cz.artin.mnp.web.pages.administrative.PortedNumbersPage, path =
4:portedNumbersFiltr:validityFiltrRadioGroup:dateFrom.PortedNumbersForm1$1
,
isVisible = true, isVersioned = false]]
Root cause:
wicket.util.convert.ConversionException: Can't convert value: 11.05.2000to
class: class java.util.Date for setting it on
[EMAIL PROTECTED]
at
wicket.util.lang.PropertyResolver$MethodGetAndSet.setValue(
PropertyResolver.java:833)
at
wicket.util.lang.PropertyResolver$ObjectAndGetSetter.setValue(
PropertyResolver.java:447)
at wicket.util.lang.PropertyResolver.setValue(PropertyResolver.java:136)
at
wicket.model.AbstractPropertyModel.onSetObject(AbstractPropertyModel.java
:182)
at
wicket.model.AbstractDetachableModel.setObject(
AbstractDetachableModel.java:131)
at wicket.Component.setModelObject(Component.java:2035)
at wicket.markup.html.form.FormComponent.updateModel(FormComponent.java
:840)
at wicket.markup.html.form.Form$11.formComponent(Form.java:917)
DateTextField is unusable for me, becouse I'am planning to have more
acceptable format for my date -
dd.MM.yyyy and dd.MM.yyyy hh:mm , maybe you can consider this to be
useful for next releases of wicket :-)
Thanks for help.
Johan Compagner wrote:
>
> you have to test to which class the converter wants to go to:
>
> public Object convert(Object o, Class c)
> {
> try
> {
> if(c == String.class)
> {
> return new
> SimpleDateFormat("dd-MM-yyyy").format((Date)o);
> }
> else
> return new
> SimpleDateFormat("dd-MM-yyyy").parse((String)o);
> }
> catch(ParseException pex)
> {
> return null;
> }
>
> or test ofcourse if the value is an instanceof date or string.
>
> We are planning to change the converter interface for the next version
of
> wicket.
> Because the current on is a bit to confusing for most people.
>
> johan
>
>
> On 3/23/06, Jaime De La Jara <[EMAIL PROTECTED]> wrote:
>>
>> Hi, I've been trying to develop an application with wicket, but I don't
>> know how to customize the date format for a textfield. I'm using the
>> DatePickercomponent but I use a different format : dd-MM-yyyy, when I
>> submit
>> the form an exception is thrown because the format is not recognized, I
>> tried to redefine the getConverter method as follows :
>>
>> TextField fecha = new TextField("fecha", Date.class)
>> {
>> public IConverter getConverter()
>> {
>> return new IConverter()
>> {
>> public Object convert(Object o, Class c)
>> {
>> try
>> {
>> return new
>>
>> SimpleDateFormat("dd-MM-yyyy").parse((String)o);
>> }
>> catch(ParseException pex)
>> {
>> return null;
>> }
>> }
>> public void setLocale(Locale loc)
>> {}
>> public Locale getLocale()
>> {
>> return Locale.getDefault();
>> }
>> };
>> }
>> } ;
>>
>> but a ClassCastException is thrown, since the method is called twice,
>> once
>> with a String value and once with a Date value. I don't know what is
>> going
>> on, any help on this would be appreciated or a simpler way to
accomplish
>> what I want to do .
>>
>> Thanks.
>>
>> ------------------------------
>> Blab-away for as little as 1ยข/min. Make PC-to-Phone
>> Calls<
http://us.rd.yahoo.com/mail_us/taglines/postman2/*http://us.rd.yahoo.com/evt=39663/*http://voice.yahoo.com
>using
>> Yahoo! Messenger with Voice.
>>
>>
>
>
--
View this message in context:
http://www.nabble.com/question-about-date-format-for-textfield-tf1330741.html#a10214688
Sent from the Wicket - User mailing list archive at Nabble.com.
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user
--
-- karthik --
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user