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?
> >
>
>
>

Reply via email to