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 using Yahoo! Messenger with Voice.


Reply via email to