You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Pills <pi...@hmcrecord.ch> on 2007/11/09 16:31:35 UTC
Strange behavior with DropDownChoice and PropertyModel
Hi,
I have a strange problem with the PropertyModel and a form. The property
model is bound with one of my class, like that:
shops = new DropDownChoice("shop", new PropertyModel(formTarget,
"shops"), new ShopDAO().findAll(), new ChoiceRenderer() {
@Override
public Object getDisplayValue(Object o) {
if (o instanceof Shop) {
Shop s = (Shop) o;
return s.getName() + " (" + s.getUrl() + ")";
}
return null;
}
});
My "formTarget" has setShop and getShop methods.
I have in this form an "edit(MyClass)" method, for editing an existing
record. It looks like this:
public void edit(MyClass l) {
[...]
shops.modelChanging();
formTarget.setShops(l.getShops());
shops.modelChanged();
[...]
And when I test it, sometimes it works fine (the drop down choice selects
the right item), and sometimes not (it selects the "null" value). I played a
little with it, and about half time there is no problem and half time the
"null" value is selected... (and I'm certain the property isn't null)
Is is a known issue? How can I fix it?
Thank you very much ;)
--
View this message in context: http://www.nabble.com/Strange-behavior-with-DropDownChoice-and-PropertyModel-tf4778358.html#a13669185
Sent from the Wicket - User mailing list archive at Nabble.com.
Re: Strange behavior with DropDownChoice and PropertyModel
Posted by Timo Rantalaiho <Ti...@ri.fi>.
On Tue, 13 Nov 2007, Pills wrote:
> Well, I use this method to edit a record. The form is bound with the field
> "formTarget". When called, it loads data in formTarget from the parameter.
>
> If I don't call modelChanging/modelChanged, some components like
> DropDownChoices aren't properly inited, and they select old cached values. I
> don't know if it is a bug or if I wrote something wrong...
Ah, maybe your formTarget.set... should be a setModelObject() instead,
so that the framework would call those methods instead.
Still I don't entirely get the point of the edit method; because
normally you just bind the objects to be edited to model (or
models) of the form and editing the form values in browser causes
them to update the properties of the objects.
Best wishes,
Timo
--
Timo Rantalaiho
Reaktor Innovations Oy <URL: http://www.ri.fi/ >
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Strange behavior with DropDownChoice and PropertyModel
Posted by Pills <pi...@hmcrecord.ch>.
Timo Rantalaiho wrote:
>
> What's the point of this method?
>
> And why is it calling modelChanging and modelChanged? I think
> that normally you don't call them themselves, just override
> them to react when the framework calls them.
>
> Best wishes,
> Timo
>
Well, I use this method to edit a record. The form is bound with the field
"formTarget". When called, it loads data in formTarget from the parameter.
If I don't call modelChanging/modelChanged, some components like
DropDownChoices aren't properly inited, and they select old cached values. I
don't know if it is a bug or if I wrote something wrong...
--
View this message in context: http://www.nabble.com/Strange-behavior-with-DropDownChoice-and-PropertyModel-tf4778358.html#a13722626
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: Strange behavior with DropDownChoice and PropertyModel
Posted by Timo Rantalaiho <Ti...@ri.fi>.
On Fri, 09 Nov 2007, Pills wrote:
> public void edit(MyClass l) {
> [...]
>
> shops.modelChanging();
> formTarget.setShops(l.getShops());
> shops.modelChanged();
>
> [...]
What's the point of this method?
And why is it calling modelChanging and modelChanged? I think
that normally you don't call them themselves, just override
them to react when the framework calls them.
Best wishes,
Timo
--
Timo Rantalaiho
Reaktor Innovations Oy <URL: http://www.ri.fi/ >
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org