i dont think you can do this globally, i would override getConverter() on the textfield thats displaying dates, or craete a DateTextField subclass that does it for you.

alternatively you can create a model decorator that does the conversion, advantage is that it will work for any component.

-Igor


On 4/7/06, Jaime De La Jara <[EMAIL PROTECTED]> wrote:

I commented the lines that define the datetostring converter
and the effect was that the date was displayed using toString()
and the float value was displayed correctly.
So, how can I define converters for different types, like
Float and Date from and to String?. In a previous post I
learnt that that the conversion was a two-way process, that
is from type1->type2 and from type2->type1, and that was
applicable to a textfield.
I'm lost here.

Jaime.




i think the problem is that you registered your own
converter for String.class so when wicket will try to
display the float in the textfield it will try to format it
to string, and it will use the datetostring converter
you registered.

-Igor


On 4/7/06, Jaime De La Jara < [EMAIL PROTECTED]> wrote:
>
> Here is the original code to define a Date format :
>
> getApplicationSettings().setConverterFactory(new IConverterFactory()
> {
> public IConverter newConverter(final Locale locale)
> {
> final Converter converter = new Converter(locale);
> // String -> Date
> DateConverter dc = new DateConverter();
> dc.setDateFormat(locale, new SimpleDateFormat("dd-MM-yyyy"));
> converter.set(Date.class, dc);
> // Date -> String
> DateToStringConverter dsc = new DateToStringConverter();
> dsc.setDateFormat(locale, new SimpleDateFormat("dd-MM-yyyy") );
> converter.set(String.class, dsc); (*)
>
> return converter;
> }
> }
> );
>
> But in this case a float value gets formatted as it were
> a Date.
> If a insert the following code in (*) :
>
> // Float -> String
> NumberToStringConverter numberToStringConverter = new NumberToStringConverter();
> DecimalFormat fmt = new
> DecimalFormat("###,###,###,###.#####");
> numberToStringConverter.setNumberFormat(locale, fmt);
> final StringConverter stringConverter = new StringConverter();
> stringConverter.set (Float.class, numberToStringConverter);
> stringConverter.set(Float.TYPE, numberToStringConverter);
> stringConverter.set(Date.class, dsc);
> converter.set(String.class, stringConverter);
> converter.set (Float.class, new FloatConverter());
>
> I get the float value correctly formmatted but the date is
> displayed using Date.toString().
>
>
> Jaime.
>
>
>
>
> can you show me youre converter code?
>
>
> On 4/6/06, Jaime De La Jara <[EMAIL PROTECTED]> wrote:
> >
> > Yes, I use the following code :
> >
> > add(new TextField("montoTotal", Float.class));
> >
> > I've made some tests and found that commenting the
> > definition of the IConverterFactory for the date format
> > and defining the format for the float field and it worked,
> > however I cannot define the format for both types.
> >
> > Thanks,
> >
> > Jaime.
> >
> >
> >
> > did you do TextField.setType(Float.class) or create it with
> > the constructor that takes the class?
> >
> > -Igor
> >
> >
> > On 4/6/06, Jaime De La Jara <[EMAIL PROTECTED] > wrote:
> > >
> > > Hi, I've just downloaded version 1.2 beta 3 and I have a
> > > problem when editing the contents of a javabean,
> > > particularly in a case of a Float field. The relevant
> > > code is :
> > >
> > > Javabean :
> > > public class Pago
> > > {
> > > .....
> > > public Float getMontoTotal()
> > > {
> > > return Float.valueOf("1234567890");
> > > }
> > > .......
> > > }
> > >
> > > Html :
> > >
> > > <td class="tit">
> > > <input wicket:id="montoTotal" type="text" class="normal" size="20"/>
> > > </td>
> > >
> > >
> > > When the page is displayed it shows the following :
> > > 15-01-1970 in the textfield,
> > > this value corresponds to the date equivalent (aprox)
> > > to the above number in milisec.
> > >
> > > The only thing I've done that can be important to this
> > > issue is to define a new IConverterFactory to apply the
> > > same date format to the whole app.
> > >
> > > What is going on?
> > >
> > > Thanks.
> > >
> > > Jaime.


Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+ countries) for 2ยข/min or less.




Reply via email to