Thanks Eelco! It looks good. The extra
TextField constructor parameter of Type will do me fine for now.
- Jon
>>> [EMAIL PROTECTED] 2005-02-21 2:31:29 PM >>> Furthermore: - you can access the currently used instance of IConverter by calling getConverter() on any component; - an instance of IConverterFactory creates the instance of IConverter to be used by the current session. There is a usefull default, but you can override this by overriding getConverterFactory() of WebApplication. E.g: /** * @see wicket.Application#getConverterFactory() */ public IConverterFactory getConverterFactory() { return new IConverterFactory() { public IConverter newConverter(final Locale locale) { final Converter converter = new Converter(locale); NumberToStringConverter numberToStringConverter = new NumberToStringConverter(); NumberFormat fmt = NumberFormat.getInstance(); fmt.setMinimumFractionDigits(2); fmt.setMaximumFractionDigits(2); numberToStringConverter.setLocale(locale); numberToStringConverter.setNumberFormat(fmt); final StringConverter stringConverter = new StringConverter(); stringConverter.set(Double.class, numberToStringConverter); stringConverter.set(Double.TYPE, numberToStringConverter); converter.set(String.class, stringConverter); return converter; } }; } Another nice thing to know is that TextField now has an extra constructor parameter, type, for if you want conversion/ validation done for you. Eelco > > > i just finished a checkin of new conversion code. API is quite a bit > different, so please examine it carefully. > > i spent all day today working on this, so please ask questions before > tweaking anything. i'm pretty sure i got this right. > > major changes: > > - folded localization into a single converter hierarchy > > - implemented converters for all primitive types plus Date and String > > - introduced ITypeConverter interface for conversions TO some implicit > type. this is mainly of > interest internally, since the IConverter interface is more general > and useful. but use of type > converters directly is supported and some mucking with > ITypeConverters may be necessary > to configure format/parse patterns for locales for your application. > > - refactored and simplified Component and TypeValidator to use the new > conversion code > this should all be automatic goodness! > > pseudo code example of converter API (again, if you're using > TypeValidator, you may not even > need to know this): > > IConverterFactory f = new ConverterFactory(); > IConverter c = f.newConverter(); > > String s = c.convert(new Integer(5), String.class); > Integer i = c.convert("5", Integer.class); > > c.setLocale(Locale.DUTCH); > String s = (String)c.convert(new Date(), String.class); > Date d = (Date)c.convert("10-okt-2002", Date.class); > > individual conversions can be registered on the Converter class by the > factory, > which is something most people won't generally need to do since > by default conversions are made available for all Java language > primitive types > and their enclosing first class objects. also conversions to and from > Date and > String are supported. all these conversions will respect Locale if > you set it > on the converter and each converter's format can be set if you don't > like the > default format for the locale. > > conversions to String are somewhat more complex internally and involve > registering > string formatting converters (which still implement the same > ITypeConverter > interface) on the StringConverter object. this is really quite > elegant and allows > for any arbitrary formatting when converting objects to strings. > currently locale > formatting for Date and Number types is supported. > ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click _______________________________________________ Wicket-user mailing list Wicket-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wicket-user ********************************************************************** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. www.katun.com ********************************************************************** |
- [Wicket-user] Converters/Formatters Jonathan Carlson
- Re: [Wicket-user] Converters/Formatters Eelco Hillenius
- Re: [Wicket-user] Converters/Formatters Eelco Hillenius
- Re: [Wicket-user] Converters/Formatters Jonathan Carlson