You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Gonzalo Aguilar Delgado <ga...@aguilardelgado.com> on 2012/05/14 17:59:36 UTC

onSelectionChanged is not calling converters

Hello, 

I've just found working with 1.5.6 that DropDownChoice control that it
may be not calling Converters. 

Because the model is still a string while calling to
onSelectionChanged(Provincia provincia) and it fails:

    Caused by: java.lang.ClassCastException: java.lang.String cannot be
cast to generated.Provincia

I have something like this:

DropDownChoice<Provincia> provinciaChoice=new
DropDownChoice<Provincia>("provincia",new WSProvinceModel()){
    ...
protected void onSelectionChanged(Provincia provincia) {
                if(provincia!=null)
                {
                	if(cityModel!=null)
                		cityModel.setProvinceId(provincia.getId().toString());
                }
}

...
};


---

In the application:
    @Override
    protected IConverterLocator newConverterLocator() {
            ConverterLocator converterLocator = new ConverterLocator();
            converterLocator.set(Provincia.class, new
ProvinciaEntryConverter());
            return converterLocator;
    }


It seems that it calls converter when setting the modelObject -> So it
converts from Provincia to String. 

But it does not when doing the oposite. Getting model does not get
converted from String to provincia.

This side of the converter never gets called.

For a shake of completeness:

The rederer.

		provinciaChoice.setChoiceRenderer(new IChoiceRenderer<Provincia>(){

			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			@Override
			public Object getDisplayValue(Provincia provincia) {
				return provincia.getDescripcion();
			}

			@Override
			public String getIdValue(Provincia provincia, int index) {
				return String.valueOf(provincia.getId());
			}
		});

Where is the problem?

I think that onSelectionChanged in DropDownChoice should call converter.

	/**
	 * Called when a selection changes.
	 */
	public final void onSelectionChanged()
	{
		convertInput();
		updateModel();
		onSelectionChanged(getModelObject());
	}






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


Re: onSelectionChanged is not calling converters

Posted by Gonzalo Aguilar Delgado <ga...@aguilardelgado.com>.
Hi Sven, 

I'm sorry. I forgot to add this to the mailing list:

I added info to the bug filled by other user.

https://issues.apache.org/jira/browse/WICKET-4353


Forget this e-mail as this is followed in the bug tracking system.

Thank you Sven.


El lun, 14-05-2012 a las 20:38 +0200, Sven Meier escribió:

> Hi,
> 
> DropDownChoice doesn't use converters, that's intended.
> 
> What default model is your choice getting/setting values from/to? Do you 
> use a CompoundPropertyModel?
> 
> Sven
> 
> 
> On 05/14/2012 05:59 PM, Gonzalo Aguilar Delgado wrote:
> > Hello,
> >
> > I've just found working with 1.5.6 that DropDownChoice control that it
> > may be not calling Converters.
> >
> > Because the model is still a string while calling to
> > onSelectionChanged(Provincia provincia) and it fails:
> >
> >      Caused by: java.lang.ClassCastException: java.lang.String cannot be
> > cast to generated.Provincia
> >
> > I have something like this:
> >
> > DropDownChoice<Provincia>  provinciaChoice=new
> > DropDownChoice<Provincia>("provincia",new WSProvinceModel()){
> >      ...
> > protected void onSelectionChanged(Provincia provincia) {
> >                  if(provincia!=null)
> >                  {
> >                  	if(cityModel!=null)
> >                  		cityModel.setProvinceId(provincia.getId().toString());
> >                  }
> > }
> >
> > ...
> > };
> >
> >
> > ---
> >
> > In the application:
> >      @Override
> >      protected IConverterLocator newConverterLocator() {
> >              ConverterLocator converterLocator = new ConverterLocator();
> >              converterLocator.set(Provincia.class, new
> > ProvinciaEntryConverter());
> >              return converterLocator;
> >      }
> >
> >
> > It seems that it calls converter when setting the modelObject ->  So it
> > converts from Provincia to String.
> >
> > But it does not when doing the oposite. Getting model does not get
> > converted from String to provincia.
> >
> > This side of the converter never gets called.
> >
> > For a shake of completeness:
> >
> > The rederer.
> >
> > 		provinciaChoice.setChoiceRenderer(new IChoiceRenderer<Provincia>(){
> >
> > 			/**
> > 			 *
> > 			 */
> > 			private static final long serialVersionUID = 1L;
> >
> > 			@Override
> > 			public Object getDisplayValue(Provincia provincia) {
> > 				return provincia.getDescripcion();
> > 			}
> >
> > 			@Override
> > 			public String getIdValue(Provincia provincia, int index) {
> > 				return String.valueOf(provincia.getId());
> > 			}
> > 		});
> >
> > Where is the problem?
> >
> > I think that onSelectionChanged in DropDownChoice should call converter.
> >
> > 	/**
> > 	 * Called when a selection changes.
> > 	 */
> > 	public final void onSelectionChanged()
> > 	{
> > 		convertInput();
> > 		updateModel();
> > 		onSelectionChanged(getModelObject());
> > 	}
> >
> >
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 

Re: onSelectionChanged is not calling converters

Posted by Sven Meier <sv...@meiers.net>.
Hi,

DropDownChoice doesn't use converters, that's intended.

What default model is your choice getting/setting values from/to? Do you 
use a CompoundPropertyModel?

Sven


On 05/14/2012 05:59 PM, Gonzalo Aguilar Delgado wrote:
> Hello,
>
> I've just found working with 1.5.6 that DropDownChoice control that it
> may be not calling Converters.
>
> Because the model is still a string while calling to
> onSelectionChanged(Provincia provincia) and it fails:
>
>      Caused by: java.lang.ClassCastException: java.lang.String cannot be
> cast to generated.Provincia
>
> I have something like this:
>
> DropDownChoice<Provincia>  provinciaChoice=new
> DropDownChoice<Provincia>("provincia",new WSProvinceModel()){
>      ...
> protected void onSelectionChanged(Provincia provincia) {
>                  if(provincia!=null)
>                  {
>                  	if(cityModel!=null)
>                  		cityModel.setProvinceId(provincia.getId().toString());
>                  }
> }
>
> ...
> };
>
>
> ---
>
> In the application:
>      @Override
>      protected IConverterLocator newConverterLocator() {
>              ConverterLocator converterLocator = new ConverterLocator();
>              converterLocator.set(Provincia.class, new
> ProvinciaEntryConverter());
>              return converterLocator;
>      }
>
>
> It seems that it calls converter when setting the modelObject ->  So it
> converts from Provincia to String.
>
> But it does not when doing the oposite. Getting model does not get
> converted from String to provincia.
>
> This side of the converter never gets called.
>
> For a shake of completeness:
>
> The rederer.
>
> 		provinciaChoice.setChoiceRenderer(new IChoiceRenderer<Provincia>(){
>
> 			/**
> 			 *
> 			 */
> 			private static final long serialVersionUID = 1L;
>
> 			@Override
> 			public Object getDisplayValue(Provincia provincia) {
> 				return provincia.getDescripcion();
> 			}
>
> 			@Override
> 			public String getIdValue(Provincia provincia, int index) {
> 				return String.valueOf(provincia.getId());
> 			}
> 		});
>
> Where is the problem?
>
> I think that onSelectionChanged in DropDownChoice should call converter.
>
> 	/**
> 	 * Called when a selection changes.
> 	 */
> 	public final void onSelectionChanged()
> 	{
> 		convertInput();
> 		updateModel();
> 		onSelectionChanged(getModelObject());
> 	}
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>


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