You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Patrick Davids <pa...@nuboit.de> on 2013/09/26 09:39:02 UTC

Wicket DropDownChoice Question about Constructors and its Behavior

Hi all,

since I'm working with Wicket I am a bit confused about the Constructors 
of DropDownChoice Class.

DropDownChoice provides Constructors without any Model or ModelObject.
e.g. (id, List choices)

This is logical in an use-case, for instance, having just a page with a 
SelectBox and my first click is about to choose something.
And I may do not have any "parent" model object of the page, so I did 
not bind my DropDownChoice by PropertyModel expressions.

So, in such cases...

Why Wicket always complaints about "try to set ModelObject of null model"?

Yes, I explicitly decided to use DropDownChoice without a model.
Since nothing is chosen, the model object of the DropDownChoice is null.
The behavior I expect is, the model object is the chosen option (object) 
after selecting one.

But it seems, it does not work like this.

Can someone please "light" me. :-)

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


Re: Wicket DropDownChoice Question about Constructors and its Behavior

Posted by Paul Borș <pa...@bors.ws>.
See section 9.2.2 "CompoundPropertyModel and model inheritance" of the Wicket Free Guide:
http://wicket.apache.org/learn/books/freeguide.html

Direct link:
https://wicket-guide.googlecode.com/files/Wicket%20free%20guide.pdf#page77

I think you're confusing components with null models (hence they look up the wicket components hierarchy for a ConpoundPropertyModel to use) with components using empty new Model() models. When you define an empty model the user input will start out blank as you would expect. The same can be done if your (Compound)PropertyModel resolves to a POJO with a property whose value is null.

If you don't specify a model at all, and none of your component's parents have a CompoundPropertyModel or they do but don't match your component's ID, then you're in troubles and you'll get you null model error.

Have a great day,
    Paul Bors

> On Sep 26, 2013, at 3:57 AM, Patrick Davids <pa...@nuboit.de> wrote:
> 
> Hmm... ok,
> does that mean, in forms I do not have to wrap my model(object) into a 
> CompundPropertyModel, because DropDownList (or even all FormComponents?) 
> automatically joins IComponentInheritedModel hierarchy?
> 
> So, as conclusion, by using a constuctor with an empty model (id, new 
> Model(), List choices) a exclude my DropDownChoice from the hierarchy?
> 
> Patrick
> 
> Am 26.09.2013 09:47, schrieb Martin Grigorov:
>> Hi,
>> 
>> This use case will work only when the DropDownChoice has a parent in the
>> hierarchy with org.apache.wicket.model.IComponentInheritedModel,
>> like org.apache.wicket.model.CompoundPropertyModel.
>> In this case the dropdown will use a slot from its parent's
>> IComponentInheritedModel.
>> 
>> 
>> On Thu, Sep 26, 2013 at 9:39 AM, Patrick Davids <pa...@nuboit.de>wrote:
>> 
>>> Hi all,
>>> 
>>> since I'm working with Wicket I am a bit confused about the Constructors
>>> of DropDownChoice Class.
>>> 
>>> DropDownChoice provides Constructors without any Model or ModelObject.
>>> e.g. (id, List choices)
>>> 
>>> This is logical in an use-case, for instance, having just a page with a
>>> SelectBox and my first click is about to choose something.
>>> And I may do not have any "parent" model object of the page, so I did
>>> not bind my DropDownChoice by PropertyModel expressions.
>>> 
>>> So, in such cases...
>>> 
>>> Why Wicket always complaints about "try to set ModelObject of null model"?
>>> 
>>> Yes, I explicitly decided to use DropDownChoice without a model.
>>> Since nothing is chosen, the model object of the DropDownChoice is null.
>>> The behavior I expect is, the model object is the chosen option (object)
>>> after selecting one.
>>> 
>>> But it seems, it does not work like this.
>>> 
>>> Can someone please "light" me. :-)
>>> 
>>> kind regards
>>> Patrick
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
> 
> -- 
> Mit freundlichen Grüßen,
> 
> Patrick Davids
> 
> NuboIT GmbH & Co. KG
> Kieler Str. 103-107 • 25474 Bönningstedt
> 
> Email: patrick.davids@nuboit.de
> 
> Handelsregister: HRA6819 Pi  | Amtsgericht Pinneberg
> 
> Geschäftsführung der Verwaltungsgesellschaft
> Daniel Fraga Zander
> 
> HRB10145Pi | Amtsgericht Pinneberg
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 

Re: Wicket DropDownChoice Question about Constructors and its Behavior

Posted by Patrick Davids <pa...@nuboit.de>.
Hmm... ok,
does that mean, in forms I do not have to wrap my model(object) into a 
CompundPropertyModel, because DropDownList (or even all FormComponents?) 
automatically joins IComponentInheritedModel hierarchy?

So, as conclusion, by using a constuctor with an empty model (id, new 
Model(), List choices) a exclude my DropDownChoice from the hierarchy?

Patrick

Am 26.09.2013 09:47, schrieb Martin Grigorov:
> Hi,
>
> This use case will work only when the DropDownChoice has a parent in the
> hierarchy with org.apache.wicket.model.IComponentInheritedModel,
> like org.apache.wicket.model.CompoundPropertyModel.
> In this case the dropdown will use a slot from its parent's
> IComponentInheritedModel.
>
>
> On Thu, Sep 26, 2013 at 9:39 AM, Patrick Davids <pa...@nuboit.de>wrote:
>
>> Hi all,
>>
>> since I'm working with Wicket I am a bit confused about the Constructors
>> of DropDownChoice Class.
>>
>> DropDownChoice provides Constructors without any Model or ModelObject.
>> e.g. (id, List choices)
>>
>> This is logical in an use-case, for instance, having just a page with a
>> SelectBox and my first click is about to choose something.
>> And I may do not have any "parent" model object of the page, so I did
>> not bind my DropDownChoice by PropertyModel expressions.
>>
>> So, in such cases...
>>
>> Why Wicket always complaints about "try to set ModelObject of null model"?
>>
>> Yes, I explicitly decided to use DropDownChoice without a model.
>> Since nothing is chosen, the model object of the DropDownChoice is null.
>> The behavior I expect is, the model object is the chosen option (object)
>> after selecting one.
>>
>> But it seems, it does not work like this.
>>
>> Can someone please "light" me. :-)
>>
>> kind regards
>> Patrick
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>

-- 
Mit freundlichen Grüßen,

Patrick Davids

NuboIT GmbH & Co. KG
Kieler Str. 103-107 • 25474 Bönningstedt

Email: patrick.davids@nuboit.de

Handelsregister: HRA6819 Pi  | Amtsgericht Pinneberg

Geschäftsführung der Verwaltungsgesellschaft
Daniel Fraga Zander

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


Re: Wicket DropDownChoice Question about Constructors and its Behavior

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

This use case will work only when the DropDownChoice has a parent in the
hierarchy with org.apache.wicket.model.IComponentInheritedModel,
like org.apache.wicket.model.CompoundPropertyModel.
In this case the dropdown will use a slot from its parent's
IComponentInheritedModel.


On Thu, Sep 26, 2013 at 9:39 AM, Patrick Davids <pa...@nuboit.de>wrote:

> Hi all,
>
> since I'm working with Wicket I am a bit confused about the Constructors
> of DropDownChoice Class.
>
> DropDownChoice provides Constructors without any Model or ModelObject.
> e.g. (id, List choices)
>
> This is logical in an use-case, for instance, having just a page with a
> SelectBox and my first click is about to choose something.
> And I may do not have any "parent" model object of the page, so I did
> not bind my DropDownChoice by PropertyModel expressions.
>
> So, in such cases...
>
> Why Wicket always complaints about "try to set ModelObject of null model"?
>
> Yes, I explicitly decided to use DropDownChoice without a model.
> Since nothing is chosen, the model object of the DropDownChoice is null.
> The behavior I expect is, the model object is the chosen option (object)
> after selecting one.
>
> But it seems, it does not work like this.
>
> Can someone please "light" me. :-)
>
> kind regards
> Patrick
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Wicket DropDownChoice Question about Constructors and its Behavior

Posted by Ernesto Reinaldo Barreiro <re...@gmail.com>.
I think if you do not provide a model wicket will try to find a parent with
a IComponentInheritedModel and use that as the model (to set the object
with the same name you passed as ID)


On Thu, Sep 26, 2013 at 9:39 AM, Patrick Davids <pa...@nuboit.de>wrote:

> Hi all,
>
> since I'm working with Wicket I am a bit confused about the Constructors
> of DropDownChoice Class.
>
> DropDownChoice provides Constructors without any Model or ModelObject.
> e.g. (id, List choices)
>
> This is logical in an use-case, for instance, having just a page with a
> SelectBox and my first click is about to choose something.
> And I may do not have any "parent" model object of the page, so I did
> not bind my DropDownChoice by PropertyModel expressions.
>
> So, in such cases...
>
> Why Wicket always complaints about "try to set ModelObject of null model"?
>
> Yes, I explicitly decided to use DropDownChoice without a model.
> Since nothing is chosen, the model object of the DropDownChoice is null.
> The behavior I expect is, the model object is the chosen option (object)
> after selecting one.
>
> But it seems, it does not work like this.
>
> Can someone please "light" me. :-)
>
> kind regards
> Patrick
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Regards - Ernesto Reinaldo Barreiro