You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Federico Fanton <ff...@ibc.it> on 2007/09/19 12:11:10 UTC

PropertyResolverConverter and non-String values

Hi everyone!
I have a form which needs to select a Class from a list, so I added a DropDownChoice loaded with a list of beans like:

public class ClassDescriptionBean{
   private String description;
   private Class type;

   [getters and setters omissis]
}

so that the form shows nice descriptions..

The form has a CompoundPropertyModel with a "back bean" like

public class BackBean{
   Class type;

   [getters and setters omissis]
}

But when I try to submit the form I have the following exception:

org.apache.wicket.util.convert.ConversionException: Can't convert value: project.ClassDescriptionBean@10721b0 to class: class java.lang.Class for setting it on project.TestComboBox$BackBean@125844f

Obviously PropertyResolverConverter doesn't know how to map a ClassDescriptionBean to the corresponding Class, but how am I supposed to do it? I already have a custom ConverterLocator in place, but it looks like it gets called only when the source (or the destination) class of the conversion is a String..
If I change BackBean.type to a ClassDescriptionBean everything works, but I'd like to add the conversion.. Am I missing something?

Many thanks for your attention!


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


Re: PropertyResolverConverter and non-String values

Posted by Federico Fanton <ff...@ibc.it>.
On Wed, 19 Sep 2007 12:32:09 +0200
"Johan Compagner" <jc...@gmail.com> wrote:

> thats final
> you could try to do something with:
> 
> protected Object convertChoiceIdToChoice(String id)

Right, sorry ^^

> But that is an id and how is that id converted to what?
> Is that the ClassDescriptionBean?

Exactly

> And that Again must be converted to something else?

Exactly again.. I the end I went with

@Override
protected Object convertChoiceIdToChoice(String id) {
    Object ret=super.convertChoiceIdToChoice(id);
    if(ret instanceof ClassDescriptionBean)
       ret=((ClassDescriptionBean)ret).getType();
    return ret;
}

Works pretty well ^^
Many thanks for your time!


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


Re: PropertyResolverConverter and non-String values

Posted by Johan Compagner <jc...@gmail.com>.
thats final
you could try to do something with:

protected Object convertChoiceIdToChoice(String id)

But that is an id and how is that id converted to what?
Is that the ClassDescriptionBean?
And that Again must be converted to something else?

johan


On 9/19/07, Federico Fanton <ff...@ibc.it> wrote:
>
> On Wed, 19 Sep 2007 12:11:10 +0200
> Federico Fanton <ff...@ibc.it> wrote:
>
> > Obviously PropertyResolverConverter doesn't know how to map a
> ClassDescriptionBean to the corresponding Class, but how am I supposed to do
> it? I already have a custom ConverterLocator in place, but it looks like it
> gets called only when the source (or the destination) class of the
> conversion is a String..
>
>
> Should I override AbstractSingleSelectChoice.convertValue() ? ^^;
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: PropertyResolverConverter and non-String values

Posted by Federico Fanton <ff...@ibc.it>.
On Wed, 19 Sep 2007 12:11:10 +0200
Federico Fanton <ff...@ibc.it> wrote:

> Obviously PropertyResolverConverter doesn't know how to map a ClassDescriptionBean to the corresponding Class, but how am I supposed to do it? I already have a custom ConverterLocator in place, but it looks like it gets called only when the source (or the destination) class of the conversion is a String..


Should I override AbstractSingleSelectChoice.convertValue() ? ^^;


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


Re: PropertyResolverConverter and non-String values

Posted by Johan Compagner <jc...@gmail.com>.
conversion is only from String->Object and Object->String
it is an in->output converter.

So how do you get an input of .ClassDescriptionBean that needs to be
converted to a Class??

johan


On 9/19/07, Federico Fanton <ff...@ibc.it> wrote:
>
> Hi everyone!
> I have a form which needs to select a Class from a list, so I added a
> DropDownChoice loaded with a list of beans like:
>
> public class ClassDescriptionBean{
>    private String description;
>    private Class type;
>
>    [getters and setters omissis]
> }
>
> so that the form shows nice descriptions..
>
> The form has a CompoundPropertyModel with a "back bean" like
>
> public class BackBean{
>    Class type;
>
>    [getters and setters omissis]
> }
>
> But when I try to submit the form I have the following exception:
>
> org.apache.wicket.util.convert.ConversionException: Can't convert value:
> project.ClassDescriptionBean@10721b0 to class: class java.lang.Class for
> setting it on project.TestComboBox$BackBean@125844f
>
> Obviously PropertyResolverConverter doesn't know how to map a
> ClassDescriptionBean to the corresponding Class, but how am I supposed to do
> it? I already have a custom ConverterLocator in place, but it looks like it
> gets called only when the source (or the destination) class of the
> conversion is a String..
> If I change BackBean.type to a ClassDescriptionBean everything works, but
> I'd like to add the conversion.. Am I missing something?
>
> Many thanks for your attention!
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>