You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Benjamin Ernst <be...@gmail.com> on 2007/08/13 14:09:05 UTC

convertToString in custom Converter is not called

Hi,

I implemented a custom Converter. It looks like this:

public class AnredeConverter implements IConverter {

    public Object convertToObject(String arg0, Locale arg1) {
        if(arg0 == null) return null;
        return Anrede.fromString(arg0);
    }

    public String convertToString(Object obj, Locale locale) {
            Anrede an = (Anrede) obj;
            return an.getValue();
    }
}


The I added it to the apllication:

@Override
    protected IConverterLocator newConverterLocator() {
        ConverterLocator converterLocator = new ConverterLocator();
        converterLocator.set(Anrede.class, new AnredeConverter());
        return converterLocator;
    }

I use it for a DropDownChoice

DropDownChoice anrede = new DropDownChoice("anrede", new PropertyModel(ma,
"anrede"), Anrede.literals());
add(anrede);

My problem is that the convertToString-Method is never called, so that the
DropDownChoice is not set to the right value.The convertToObject-Method
works fine.

How can I tell the DropDownChoice to use the Converter to get the right
value.

Thanks in advance,
Benjamin

Re: convertToString in custom Converter is not called

Posted by Johan Compagner <jc...@gmail.com>.
Why are you using such an old thread that talkes about Abstractchoice?

I see that you use ConverterLocator. and i think thats 1.3. But then you
don't need
to have StringToX and XtoString

Because the converter can do both ways.

And thats also you problem
Because you have to override the same method in StringToUser because
that converter is registered under User.class

johan



On Nov 20, 2007 12:19 AM, narup <ps...@wsgc.com> wrote:

>
> for more details i have a converter
>  public class UserConverter extends ConverterLocator {
>        private static final long serialVersionUID = 1L;
>
>        public UserConverter () {
>            super();
>            set(User.class, new StringToUserConverter());
>            set(String.class, new UserToStringConverter());
>        }
>    }
>
> and also in UserToStringConverter class i have overriden convertToString
> method of AbstractConverter but it uses the convertToString from
> AbstractConverter class only.
>
>
>
> narup wrote:
> >
> > Hello All,
> > I am also having a problem with custom converter, convertToString method
> > is never called.
> >
> > Thanks
> >
> >
> > igor.vaynberg wrote:
> >>
> >> afik ddcs dont use converters because they use a choice renderer.
> >> see ddc.setchoicerenderer();
> >> -igor
> >>
> >>
> >> On 8/13/07, Benjamin Ernst <be...@gmail.com> wrote:
> >>>
> >>> Hi,
> >>>
> >>> I implemented a custom Converter. It looks like this:
> >>>
> >>> public class AnredeConverter implements IConverter {
> >>>
> >>>     public Object convertToObject(String arg0, Locale arg1) {
> >>>         if(arg0 == null) return null;
> >>>         return Anrede.fromString(arg0);
> >>>     }
> >>>
> >>>     public String convertToString(Object obj, Locale locale) {
> >>>             Anrede an = (Anrede) obj;
> >>>             return an.getValue();
> >>>     }
> >>> }
> >>>
> >>>
> >>> The I added it to the apllication:
> >>>
> >>> @Override
> >>>     protected IConverterLocator newConverterLocator() {
> >>>         ConverterLocator converterLocator = new ConverterLocator();
> >>>         converterLocator.set(Anrede.class, new AnredeConverter());
> >>>         return converterLocator;
> >>>     }
> >>>
> >>> I use it for a DropDownChoice
> >>>
> >>> DropDownChoice anrede = new DropDownChoice("anrede", new
> >>> PropertyModel(ma,
> >>> "anrede"), Anrede.literals());
> >>> add(anrede);
> >>>
> >>> My problem is that the convertToString-Method is never called, so that
> >>> the
> >>> DropDownChoice is not set to the right value.TheconvertToObject-Method
> >>> works fine.
> >>>
> >>> How can I tell the DropDownChoice to use the Converter to get the
> right
> >>> value.
> >>>
> >>> Thanks in advance,
> >>> Benjamin
> >>>
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/convertToString-in-custom-Converter-is-not-called-tf4260835.html#a13847801
>  Sent from the Wicket - User mailing list archive at Nabble.com<http://nabble.com/>
> .
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: convertToString in custom Converter is not called

Posted by narup <ps...@wsgc.com>.
for more details i have a converter 
 public class UserConverter extends ConverterLocator {
        private static final long serialVersionUID = 1L;

        public UserConverter () {
            super();
            set(User.class, new StringToUserConverter());
            set(String.class, new UserToStringConverter());
        }
    }

and also in UserToStringConverter class i have overriden convertToString
method of AbstractConverter but it uses the convertToString from
AbstractConverter class only.



narup wrote:
> 
> Hello All,
> I am also having a problem with custom converter, convertToString method
> is never called.
> 
> Thanks 
> 
> 
> igor.vaynberg wrote:
>> 
>> afik ddcs dont use converters because they use a choice renderer.
>> see ddc.setchoicerenderer();
>> -igor
>> 
>> 
>> On 8/13/07, Benjamin Ernst <be...@gmail.com> wrote:
>>>
>>> Hi,
>>>
>>> I implemented a custom Converter. It looks like this:
>>>
>>> public class AnredeConverter implements IConverter {
>>>
>>>     public Object convertToObject(String arg0, Locale arg1) {
>>>         if(arg0 == null) return null;
>>>         return Anrede.fromString(arg0);
>>>     }
>>>
>>>     public String convertToString(Object obj, Locale locale) {
>>>             Anrede an = (Anrede) obj;
>>>             return an.getValue();
>>>     }
>>> }
>>>
>>>
>>> The I added it to the apllication:
>>>
>>> @Override
>>>     protected IConverterLocator newConverterLocator() {
>>>         ConverterLocator converterLocator = new ConverterLocator();
>>>         converterLocator.set(Anrede.class, new AnredeConverter());
>>>         return converterLocator;
>>>     }
>>>
>>> I use it for a DropDownChoice
>>>
>>> DropDownChoice anrede = new DropDownChoice("anrede", new
>>> PropertyModel(ma,
>>> "anrede"), Anrede.literals());
>>> add(anrede);
>>>
>>> My problem is that the convertToString-Method is never called, so that
>>> the
>>> DropDownChoice is not set to the right value.The convertToObject-Method
>>> works fine.
>>>
>>> How can I tell the DropDownChoice to use the Converter to get the right
>>> value.
>>>
>>> Thanks in advance,
>>> Benjamin
>>>
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/convertToString-in-custom-Converter-is-not-called-tf4260835.html#a13847801
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: convertToString in custom Converter is not called

Posted by narup <ps...@wsgc.com>.
Hello All,
I am also having a problem with custom converter, convertToString method is
never called.

Thanks 


igor.vaynberg wrote:
> 
> afik ddcs dont use converters because they use a choice renderer.
> see ddc.setchoicerenderer();
> -igor
> 
> 
> On 8/13/07, Benjamin Ernst <be...@gmail.com> wrote:
>>
>> Hi,
>>
>> I implemented a custom Converter. It looks like this:
>>
>> public class AnredeConverter implements IConverter {
>>
>>     public Object convertToObject(String arg0, Locale arg1) {
>>         if(arg0 == null) return null;
>>         return Anrede.fromString(arg0);
>>     }
>>
>>     public String convertToString(Object obj, Locale locale) {
>>             Anrede an = (Anrede) obj;
>>             return an.getValue();
>>     }
>> }
>>
>>
>> The I added it to the apllication:
>>
>> @Override
>>     protected IConverterLocator newConverterLocator() {
>>         ConverterLocator converterLocator = new ConverterLocator();
>>         converterLocator.set(Anrede.class, new AnredeConverter());
>>         return converterLocator;
>>     }
>>
>> I use it for a DropDownChoice
>>
>> DropDownChoice anrede = new DropDownChoice("anrede", new
>> PropertyModel(ma,
>> "anrede"), Anrede.literals());
>> add(anrede);
>>
>> My problem is that the convertToString-Method is never called, so that
>> the
>> DropDownChoice is not set to the right value.The convertToObject-Method
>> works fine.
>>
>> How can I tell the DropDownChoice to use the Converter to get the right
>> value.
>>
>> Thanks in advance,
>> Benjamin
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/convertToString-in-custom-Converter-is-not-called-tf4260835.html#a13847626
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: convertToString in custom Converter is not called

Posted by Ryan Holmes <ry...@hyperstep.com>.
They use choice renderers as well as converters.  
IChoiceRenderer.getDisplayValue returns an Object that gets converted  
to a string. This is from AbstractChoice in Wicket 1.2:

	protected void appendOptionHtml(AppendingStringBuffer buffer, Object  
choice, int index,
			String selected)
	{
		final String displayValue = (String)getConverter().convert(
				renderer.getDisplayValue(choice), String.class);
...


Has this changed in 1.3?

-Ryan


On Aug 13, 2007, at 8:14 AM, Igor Vaynberg wrote:

> afik ddcs dont use converters because they use a choice renderer.
> see ddc.setchoicerenderer();
> -igor
>
>
> On 8/13/07, Benjamin Ernst <be...@gmail.com> wrote:
>>
>> Hi,
>>
>> I implemented a custom Converter. It looks like this:
>>
>> public class AnredeConverter implements IConverter {
>>
>>     public Object convertToObject(String arg0, Locale arg1) {
>>         if(arg0 == null) return null;
>>         return Anrede.fromString(arg0);
>>     }
>>
>>     public String convertToString(Object obj, Locale locale) {
>>             Anrede an = (Anrede) obj;
>>             return an.getValue();
>>     }
>> }
>>
>>
>> The I added it to the apllication:
>>
>> @Override
>>     protected IConverterLocator newConverterLocator() {
>>         ConverterLocator converterLocator = new ConverterLocator();
>>         converterLocator.set(Anrede.class, new AnredeConverter());
>>         return converterLocator;
>>     }
>>
>> I use it for a DropDownChoice
>>
>> DropDownChoice anrede = new DropDownChoice("anrede", new  
>> PropertyModel(ma,
>> "anrede"), Anrede.literals());
>> add(anrede);
>>
>> My problem is that the convertToString-Method is never called, so  
>> that the
>> DropDownChoice is not set to the right value.The convertToObject- 
>> Method
>> works fine.
>>
>> How can I tell the DropDownChoice to use the Converter to get the  
>> right
>> value.
>>
>> Thanks in advance,
>> Benjamin
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: convertToString in custom Converter is not called

Posted by Igor Vaynberg <ig...@gmail.com>.
afik ddcs dont use converters because they use a choice renderer.
see ddc.setchoicerenderer();
-igor


On 8/13/07, Benjamin Ernst <be...@gmail.com> wrote:
>
> Hi,
>
> I implemented a custom Converter. It looks like this:
>
> public class AnredeConverter implements IConverter {
>
>     public Object convertToObject(String arg0, Locale arg1) {
>         if(arg0 == null) return null;
>         return Anrede.fromString(arg0);
>     }
>
>     public String convertToString(Object obj, Locale locale) {
>             Anrede an = (Anrede) obj;
>             return an.getValue();
>     }
> }
>
>
> The I added it to the apllication:
>
> @Override
>     protected IConverterLocator newConverterLocator() {
>         ConverterLocator converterLocator = new ConverterLocator();
>         converterLocator.set(Anrede.class, new AnredeConverter());
>         return converterLocator;
>     }
>
> I use it for a DropDownChoice
>
> DropDownChoice anrede = new DropDownChoice("anrede", new PropertyModel(ma,
> "anrede"), Anrede.literals());
> add(anrede);
>
> My problem is that the convertToString-Method is never called, so that the
> DropDownChoice is not set to the right value.The convertToObject-Method
> works fine.
>
> How can I tell the DropDownChoice to use the Converter to get the right
> value.
>
> Thanks in advance,
> Benjamin
>