You could see my blog post [1] and adapt the DefaultIfNullModel to fit
your needs.  Then just wrap your property model in your newly created
model.  Or extend PropertyModel, override getObject and implement this
in your own custom property model.  I prefer composition over
inheritance because you can reuse it more places - but it's your call.

[1] - 
http://www.jeremythomerson.com/blog/2008/11/06/wicket-the-power-of-nested-models/

--
Jeremy Thomerson
http://www.wickettraining.com




On Tue, Jun 9, 2009 at 12:42 PM, Guillaume Simard<[email protected]> wrote:
> Hi everyone !
> I have two questions.
>
> First, I have a PropertyModel ..
>
> Something similar to this :
>
> add ( new Label("firstResidentName", new PropertyModel<House>(myHouse,
> "residents[0].name") ) );
>
> Where House.getResidents() returns a Collection<Person>
> and Person.getName() returns the Person's name (a String).
>
> Now say I use this PropertyModel on a House with no residents. I'll get
> a IndexOutOfBoundsException.
> Is there a way to define a default value for the Label in case the
> PropertyModel cannot reach the property ?
>
> In my current situation, I cannot verify directly (before defining the
> PropertyModel) if "myHouse" has any residents so the solution would have to
> be related to the Label or the Model.
>
> Second,
>
> Using the same example, should my PropertyModel be " PropertyModel<House> "
> or " PropertyModel<String> " ? Person.getName() returns a String.
>
> Thanks in advance !
>
> Sincerely,
> Guillaume
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to