All,

There have been a couple of questions about custom conversion lately.
I've looked into it a bit, and came to the conclusion that we should
re-evaluate how our conversion works for Wicket 1.3
(https://sourceforge.net/tracker/?func=detail&atid=684975&aid=1453022&group_id=119783).

For now, I added some convenience converters, specifically for use
when you want to provide a custom converter for a single component.
This is from the FormInput example of wicket-examples, and hopefully
illustrates it's use. BEFORE YOU USE IT THOSE CONVERTERS, DO READ
THEIR JAVADOCS PLEASE.

                        // TextField using a custom converter.
                        add(new TextField("urlProperty", URL.class)
                        {
                                public IConverter getConverter()
                                {
                                        return new SimpleConverterAdapter()
                                        {
                                                public String toString(Object 
value)
                                                {
                                                        return value != null ? 
value.toString() : null;
                                                }

                                                public Object toObject(String 
value)
                                                {
                                                        try
                                                        {
                                                                return new 
URL(value.toString());
                                                        }
                                                        catch 
(MalformedURLException e)
                                                        {
                                                                throw new 
ConversionException("'" + value + "' is not a valid URL");
                                                        }
                                                }
                                        };
                                }
                        });

                        // TextField using a mask converter
                        add(new TextField("phoneNumberUS", UsPhoneNumber.class)
                        {
                                public IConverter getConverter()
                                {
                                        // US telephone number mask
                                        return new MaskConverter("(###) 
###-####", UsPhoneNumber.class);
                                }
                        });


I hope this will make things a bit easier for those people that were
struggeling with custom conversion,

Eelco


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to