You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Lucio Crusca <lu...@sulweb.org> on 2013/02/14 11:55:06 UTC
DropDownChoice not updating model
Hello *,
I have a FormComponentPanel derived class that uses a DropDownChoice with a
ChoiceRenderer. The DropDownChoice id matches the field name in my model class
and I use a CompountPropertyModel wrapping my model instance for the
component.
Code snippets:
class StreetAddress
...
private String address;
@ManyToOne
private District idDistrict;
... usual getters and setters
class StreetAddressFormCP extends FormComponentPanel<StreetAddress>
...
super(myCompountPropertyModel));
add(new TextField("address"));
add(new DropDownChoice("idDistrict", ...));
class StreetAddressForm extends Form<StreetAddress>
...
super(myCompoundPropertyModel);
add(new StreetAddressFormCP(myCompoundPropertyModel));
...
All seems to work except that when I edit an address and change district in
the dropdown, my onSubmit receives a model with the old value for idDistrict
(but new edited value for address), so that part of the edit is lost.
Isn't DropDownChoice supposed to always update the model when the user selects
an item/submits the form?
P.S. onSubmit overridden on a Button behaves like stated above, while onSubmit
overridden on the Form behaves differently: it receives a model with a null
target...
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: DropDownChoice not updating model
Posted by Ernesto Reinaldo Barreiro <re...@gmail.com>.
Thanks for pointing that out!
On Thu, Feb 14, 2013 at 12:21 PM, Sven Meier <sv...@meiers.net> wrote:
> If you use objects without overriden #equals() and #hashcode() and
> DropDownChoice you have several options:
> 1) use a custom ChoiceRenderer
> 2) override AbstractSingleSelectChoice#**getModelValue()
> 3) make sure the selected choice is the identical object contained in the
> choices list (e.g. via OpenSessionInView)
>
> https://issues.apache.org/**jira/browse/WICKET-4353<https://issues.apache.org/jira/browse/WICKET-4353>might give you more information.
>
> Best regards
> Sven
>
>
> On 02/14/2013 12:01 PM, Ernesto Reinaldo Barreiro wrote:
>
>> I don't know if this has anything to do... but make sure
>> class StreetAddress implements equals
>>
>> On Thu, Feb 14, 2013 at 11:55 AM, Lucio Crusca <lu...@sulweb.org> wrote:
>>
>> Hello *,
>>>
>>> I have a FormComponentPanel derived class that uses a DropDownChoice
>>> with a
>>> ChoiceRenderer. The DropDownChoice id matches the field name in my model
>>> class
>>> and I use a CompountPropertyModel wrapping my model instance for the
>>> component.
>>>
>>> Code snippets:
>>>
>>> class StreetAddress
>>> ...
>>> private String address;
>>> @ManyToOne
>>> private District idDistrict;
>>>
>>> ... usual getters and setters
>>>
>>>
>>> class StreetAddressFormCP extends FormComponentPanel<**StreetAddress>
>>> ...
>>> super(myCompountPropertyModel)**);
>>> add(new TextField("address"));
>>> add(new DropDownChoice("idDistrict", ...));
>>>
>>> class StreetAddressForm extends Form<StreetAddress>
>>> ...
>>> super(myCompoundPropertyModel)**;
>>> add(new StreetAddressFormCP(**myCompoundPropertyModel));
>>> ...
>>>
>>>
>>> All seems to work except that when I edit an address and change district
>>> in
>>> the dropdown, my onSubmit receives a model with the old value for
>>> idDistrict
>>> (but new edited value for address), so that part of the edit is lost.
>>>
>>> Isn't DropDownChoice supposed to always update the model when the user
>>> selects
>>> an item/submits the form?
>>>
>>> P.S. onSubmit overridden on a Button behaves like stated above, while
>>> onSubmit
>>> overridden on the Form behaves differently: it receives a model with a
>>> null
>>> target...
>>>
>>> ------------------------------**------------------------------**
>>> ---------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.**apache.org<us...@wicket.apache.org>
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>>
>>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@wicket.**apache.org<us...@wicket.apache.org>
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
--
Regards - Ernesto Reinaldo Barreiro
Antilia Soft
http://antiliasoft.com/ <http://antiliasoft.com/antilia>
Re: DropDownChoice not updating model
Posted by Sven Meier <sv...@meiers.net>.
> You are so f***ing smart :)
Sometimes :P.
Sven
On 02/15/2013 04:43 PM, Lucio Crusca wrote:
> In data Thursday 14 February 2013 12:59:05, Sven Meier ha scritto:
>> Then the DropDownChoice should work fine.
>>
>> Try to create a quickstart please.
> You are so f***ing smart :)
>
> The quickstart just worked and showed me what I was doing wrong, basically
> this:
>
> District currentSelection = ... // retrieve current district from database
> if (currentSelection != null)
> myDropDownChoice.setModel(new CompoundPropertyModel(currentSelection));
>
> which is a plain blunder because I was changing the model under the hood. The
> fix was quite easy: cut away those lines, since DropDownChoice already takes
> care of showing the currently selected item.
>
> Thanks.
>
> ---------------------------------------------------------------------
> 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: DropDownChoice not updating model
Posted by Lucio Crusca <lu...@sulweb.org>.
In data Thursday 14 February 2013 12:59:05, Sven Meier ha scritto:
> Then the DropDownChoice should work fine.
>
> Try to create a quickstart please.
You are so f***ing smart :)
The quickstart just worked and showed me what I was doing wrong, basically
this:
District currentSelection = ... // retrieve current district from database
if (currentSelection != null)
myDropDownChoice.setModel(new CompoundPropertyModel(currentSelection));
which is a plain blunder because I was changing the model under the hood. The
fix was quite easy: cut away those lines, since DropDownChoice already takes
care of showing the currently selected item.
Thanks.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: DropDownChoice not updating model
Posted by Sven Meier <sv...@meiers.net>.
Then the DropDownChoice should work fine.
Try to create a quickstart please.
Sven
On 02/14/2013 12:53 PM, Lucio Crusca wrote:
> In data giovedì 14 febbraio 2013 12:21:58, Sven Meier ha scritto:
>> On 02/14/2013 12:01 PM, Ernesto Reinaldo Barreiro wrote:
>>> I don't know if this has anything to do... but make sure
>>> class StreetAddress implements equals
>> If you use objects without overriden #equals() and #hashcode() and
>> DropDownChoice you have several options:
> My StreetAddress and District classes DO have #equals() and #hashcode()
> overridden. Both #equals() check against the id (coming from the database) and
> their code has been generated by hibernate tools automatically. They contain a
> warning about cases where the id is not set (new District()...), but I think
> that could not do any harm to DropDownChoice in my case, since all the items
> are being loaded from the database and they have an id set for sure (it's the
> primary key).
>
>
> ---------------------------------------------------------------------
> 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: DropDownChoice not updating model
Posted by Lucio Crusca <lu...@sulweb.org>.
In data giovedì 14 febbraio 2013 12:21:58, Sven Meier ha scritto:
> On 02/14/2013 12:01 PM, Ernesto Reinaldo Barreiro wrote:
> > I don't know if this has anything to do... but make sure
> > class StreetAddress implements equals
>
> If you use objects without overriden #equals() and #hashcode() and
> DropDownChoice you have several options:
My StreetAddress and District classes DO have #equals() and #hashcode()
overridden. Both #equals() check against the id (coming from the database) and
their code has been generated by hibernate tools automatically. They contain a
warning about cases where the id is not set (new District()...), but I think
that could not do any harm to DropDownChoice in my case, since all the items
are being loaded from the database and they have an id set for sure (it's the
primary key).
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: DropDownChoice not updating model
Posted by Sven Meier <sv...@meiers.net>.
If you use objects without overriden #equals() and #hashcode() and
DropDownChoice you have several options:
1) use a custom ChoiceRenderer
2) override AbstractSingleSelectChoice#getModelValue()
3) make sure the selected choice is the identical object contained in
the choices list (e.g. via OpenSessionInView)
https://issues.apache.org/jira/browse/WICKET-4353 might give you more
information.
Best regards
Sven
On 02/14/2013 12:01 PM, Ernesto Reinaldo Barreiro wrote:
> I don't know if this has anything to do... but make sure
> class StreetAddress implements equals
>
> On Thu, Feb 14, 2013 at 11:55 AM, Lucio Crusca <lu...@sulweb.org> wrote:
>
>> Hello *,
>>
>> I have a FormComponentPanel derived class that uses a DropDownChoice with a
>> ChoiceRenderer. The DropDownChoice id matches the field name in my model
>> class
>> and I use a CompountPropertyModel wrapping my model instance for the
>> component.
>>
>> Code snippets:
>>
>> class StreetAddress
>> ...
>> private String address;
>> @ManyToOne
>> private District idDistrict;
>>
>> ... usual getters and setters
>>
>>
>> class StreetAddressFormCP extends FormComponentPanel<StreetAddress>
>> ...
>> super(myCompountPropertyModel));
>> add(new TextField("address"));
>> add(new DropDownChoice("idDistrict", ...));
>>
>> class StreetAddressForm extends Form<StreetAddress>
>> ...
>> super(myCompoundPropertyModel);
>> add(new StreetAddressFormCP(myCompoundPropertyModel));
>> ...
>>
>>
>> All seems to work except that when I edit an address and change district in
>> the dropdown, my onSubmit receives a model with the old value for
>> idDistrict
>> (but new edited value for address), so that part of the edit is lost.
>>
>> Isn't DropDownChoice supposed to always update the model when the user
>> selects
>> an item/submits the form?
>>
>> P.S. onSubmit overridden on a Button behaves like stated above, while
>> onSubmit
>> overridden on the Form behaves differently: it receives a model with a null
>> target...
>>
>> ---------------------------------------------------------------------
>> 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: DropDownChoice not updating model
Posted by Ernesto Reinaldo Barreiro <re...@gmail.com>.
I don't know if this has anything to do... but make sure
class StreetAddress implements equals
On Thu, Feb 14, 2013 at 11:55 AM, Lucio Crusca <lu...@sulweb.org> wrote:
> Hello *,
>
> I have a FormComponentPanel derived class that uses a DropDownChoice with a
> ChoiceRenderer. The DropDownChoice id matches the field name in my model
> class
> and I use a CompountPropertyModel wrapping my model instance for the
> component.
>
> Code snippets:
>
> class StreetAddress
> ...
> private String address;
> @ManyToOne
> private District idDistrict;
>
> ... usual getters and setters
>
>
> class StreetAddressFormCP extends FormComponentPanel<StreetAddress>
> ...
> super(myCompountPropertyModel));
> add(new TextField("address"));
> add(new DropDownChoice("idDistrict", ...));
>
> class StreetAddressForm extends Form<StreetAddress>
> ...
> super(myCompoundPropertyModel);
> add(new StreetAddressFormCP(myCompoundPropertyModel));
> ...
>
>
> All seems to work except that when I edit an address and change district in
> the dropdown, my onSubmit receives a model with the old value for
> idDistrict
> (but new edited value for address), so that part of the edit is lost.
>
> Isn't DropDownChoice supposed to always update the model when the user
> selects
> an item/submits the form?
>
> P.S. onSubmit overridden on a Button behaves like stated above, while
> onSubmit
> overridden on the Form behaves differently: it receives a model with a null
> target...
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
--
Regards - Ernesto Reinaldo Barreiro
Antilia Soft
http://antiliasoft.com/ <http://antiliasoft.com/antilia>