Could you send us your converter? I think it is a good idea to keep this discussion on the list, so that other (future) users can also follow it.

Eelco

Gili wrote:


I'd like to discuss this issue online with one of you, preferrably over MSN, AOL, or Yahoo messenger.


I am using BoundCompoundPropertyModel so if I understand you correctly then the conversion should be automatic. I provided my own converter, which I register using:

Converter converter = (Converter) getConverter();
converter.set(InternetAddress.class, new InternetAddressConverter());

from within the Form. Aside from that, what else could be going wrong?

Gili


Eelco Hillenius wrote:

I don't know what your problem is; I need more code.

Anyway, here are a few hints for working with converters in general:
- be sure conversion works two ways. Generally you have to have a converter for get- and one for setObject;
- conversion is only automatic when you use the PropertyModels (the ones that use Ognl);
- if you only support one locale (which is the case in a lot of my projects), you might want to pin down the locale.
- in order to make converters work throughout your application, override the factory method in your application class like:


/**
* @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(locale);
fmt.setMinimumFractionDigits(2);
fmt.setMaximumFractionDigits(2);
numberToStringConverter.setNumberFormat(locale, fmt);
final StringConverter stringConverter = new StringConverter();
stringConverter.set(Double.class, numberToStringConverter);
stringConverter.set(Double.TYPE, numberToStringConverter);
converter.set(String.class, stringConverter);
return converter;
}
};
}


Regards,

Eelco

(I'll contact you personally for more code)


Gili wrote:


Ok, I've defined convert() and added my converter to the default one but now I get this exception:


ognl.OgnlException: email [java.lang.ClassCastException: [Ljavax.mail.internet.InternetAddress;]
at ognl.ObjectPropertyAccessor.setPossibleProperty(ObjectPropertyAccessor.java:84)


at ognl.ObjectPropertyAccessor.setProperty(ObjectPropertyAccessor.java:132)

at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:1629)
at ognl.ASTProperty.setValueBody(ASTProperty.java:105)
at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:180)
at ognl.SimpleNode.setValue(SimpleNode.java:249)
at ognl.Ognl.setValue(Ognl.java:476)
at ognl.Ognl.setValue(Ognl.java:494)
at wicket.model.AbstractPropertyModel.onSetObject(AbstractPropertyModel.java:184)



The model contains this method:

public void setEmail(InternetAddress value)

    The Form contains this constructor:

    public SubscriptionForm(String name, IFeedback feedback)
    {
      super(name, feedback);

BoundCompoundPropertyModel model = new BoundCompoundPropertyModel(new SubscriptionModel());
setModel(model);


Converter converter = (Converter) getConverter();
converter.set(InternetAddress.class, new InternetAddressConverter());
RequiredTextField email = new RequiredTextField("email", InternetAddress.class);
add(email);


      model.bind(email, InternetAddress.class);
      add(new Button("submit"));
    }

    Ideas?

Gili

Gili wrote:

Hi,

I need help with Wicket converters. I took a quick glance at AbstractConverter and it does not define:

Object convert(Object value, Locale locale)

which is defined by subclasses. This is confusing to me because I want to define a InternetAddressConverter which will ensure that a String field in the form is actually a valid email address. It is unclear to me what I need to do to get this to work. Any tips would be appreciated.

Gili




-------------------------------------------------------
This SF.Net email is sponsored by: New Crystal Reports XI.
Version 11 adds new functionality designed to reduce time involved in
creating, integrating, and deploying reporting solutions. Free runtime info,
new features, or free trial, at: http://www.businessobjects.com/devxi/728
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user






-------------------------------------------------------
This SF.Net email is sponsored by: New Crystal Reports XI.
Version 11 adds new functionality designed to reduce time involved in
creating, integrating, and deploying reporting solutions. Free runtime info,
new features, or free trial, at: http://www.businessobjects.com/devxi/728
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user





-------------------------------------------------------
This SF.Net email is sponsored by: New Crystal Reports XI.
Version 11 adds new functionality designed to reduce time involved in
creating, integrating, and deploying reporting solutions. Free runtime info,
new features, or free trial, at: http://www.businessobjects.com/devxi/728
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user




-------------------------------------------------------
This SF.Net email is sponsored by: New Crystal Reports XI.
Version 11 adds new functionality designed to reduce time involved in
creating, integrating, and deploying reporting solutions. Free runtime info,
new features, or free trial, at: http://www.businessobjects.com/devxi/728
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to