Clint Thanks for your help. This is exactly what I needed. Mike -----Original Message----- From: Igor Vaynberg [mailto:[email protected]] Sent: Friday, April 01, 2011 1:45 AM To: [email protected] Cc: Clint Checketts Subject: Re: Wicket help
as long as you dont give all of it away :) -igor On Thu, Mar 31, 2011 at 7:04 PM, Clint Checketts <[email protected]> wrote: > Mike, > > Yes, it would make your code a bit easier to read (and maintain) if > you sub-classed DoubleConverter. > > Also another tip from the Wicket Cookbook (pg 27): > > You can register converters in your wicket application. This way all > formcomponents that are converting Double (or a given type) will use > your customer converter. That will keep you from having to override > getConverter every time. > > public class WicketApplication extends WebApplication { > protected IConverterLocator newConverterLocator() { > ConverterLocator locator = > (ConverterLocator)super.newConverterLocator(); > locator.set(Double.class, new MikesDoubleConverter()); > return locator; > } > > > I hope Igor doesn't mind me sharing all the great tips in his book. I > sound like a walking advertisement. > > -Clint > > > On Thu, Mar 31, 2011 at 7:01 PM, Henry, Mike [GCG-PFS] < > [email protected]> wrote: > >> So I have a bunch of these fields and I assume your suggesting >> subclassing DoubleConverter() and building in this functionality? >> Then I can just add the override for getConverter() and return new >> myDoubleConverter()? Thanks for the help I think Igor just sold >> another book. >> >> -----Original Message----- >> From: Clint Checketts [mailto:[email protected]] >> Sent: Thursday, March 31, 2011 6:59 PM >> To: [email protected] >> Subject: Re: Wicket help >> >> The magic is calling setVariable on the ConversionException. Thanks >> to Igor's new book >> <https://www.packtpub.com/apache-wicket-cookbook/book> >> for teaching me that. ;) >> >> So in your page's property file you'd have (you had the wrong case on >> *IC*onverter in your last email): >> mortgageAmountPrimary.IConverter.Double=You must enter a valid value >> for ${user}'s mortgage amount field to continue with this application. >> >> Java code: >> form.add(new >> TextField<Double>("mortgageAmountPrimary",Double.class){ >> >> @Override >> public IConverter getConverter(Class<?> type) >> { >> return new DoubleConverter(){ >> >> @Override >> public Double convertToObject(String value, Locale >> locale) >> { >> try{ >> return super.convertToObject(value, >> locale); >> }catch(ConversionException e){ >> * e.setVariable("user", "Theos");* >> throw e; >> } >> } >> }; >> } >> }); >> >> >> I did it all inline so you could see it. But subclassing to make it >> more useable, like getting the variable's value via a passed in Model >> wouldn't hurt. >> >> -Clint >> >> >> On Thu, Mar 31, 2011 at 4:54 PM, Henry, Mike [GCG-PFS] < >> [email protected]> wrote: >> >> > I have: >> > TextField mortgageAmountPrimary = new >> > TextField("mortgageAmountPrimary", >> > Double.class); >> > >> > If the built in double conversion fails I want this custom error >> > message: >> > >> > "You must enter a valid value for Ted's mortgage amount field to >> > continue with this application." >> > >> > I need to pass in "Ted" in a variable like: >> > mortgageAmountPrimary.Iconverter.Double=You must enter a valid >> > value for ${username}'s mortgage amount field to continue with this >> application. >> > >> > So I need a 'username' var to pass in. Can you extend a converter >> > and if so how would you instruct the textfield to use it? >> > Thanks >> > >> > -----Original Message----- >> > From: Jered Myers [mailto:[email protected]] >> > Sent: Thursday, March 31, 2011 3:39 PM >> > To: [email protected] >> > Subject: Re: Wicket help >> > >> > I think you might be looking for the variablesMap(IValidatable) >> > function in AbstractValidator. You will probably need to extend >> > your validator and override that function. PatternValidator >> > overrides it to create the "pattern" variable, if you want an example. >> > >> > On 3/31/2011 10:57 AM, Henry, Mike [GCG-PFS] wrote: >> > > Does anyone know if its possible to add your own variables to the >> > > built it converters/validators for custom messages? >> > > >> > >> > >> > >> >> >
