Returning a new ArrayList() would be dangerous, as add()ing to it would have no
effect on the ListView, as it is not in the Model, and, as Johan said, asking
for the List shouldn't set the Model. getList() should either return null, or
stay as it is. Either of these allows the user to do a test (instead of
catching an exception) before proceeding. I don't think
'getList().add(someObject)' can safely be implemented, and this should be
documented. You just have to resign yourself to:
List myList = myListView.getList();
if (myList != Collections.EMPTY_LIST) mylist.add(someObject);
/* or, if changed to return 'null' */
if (myList != null) mylist.add(someObject);
At least returning Collections.EMPTY_LIST allows some tests to work directly,
such as:
if (myListView.getList().size() > 0) {...}
OTOH, convenience is all well and good, but at least if you return (and user
tests for test for) 'null', then you always *know* that there is no underlying
List, whatever List method you want to use.
I reckon returning null would be better.
-S.
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Eelco Hillenius
Sent: 16 September 2005 08:06
To: [email protected]
Subject: Re: [Wicket-user] Possible ListView Bug
Ah, yes... interesting. Maybe it /is/ better to return null or a new ArrayList.
Eelco
On 9/16/05, Nick Heudecker <[EMAIL PROTECTED]> wrote:
> That fails anyway because Collections.EMPTY_LIST is an AbstractList.
> AbstractList#add(Object) throws an exception.
>
>
> On 9/15/05, Igor Vaynberg < [EMAIL PROTECTED]> wrote:
> >
> >
> >
> > True, but a reasonable behavior is:
> >
> > getList().add(some object) which fails if model object is null.
> >
> > -Igor
> >
> >
> >
> >
> >
> >
> > ________________________________
>
> >
> > From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf
> Of Johan Compagner
> > Sent: Thursday, September 15, 2005 4:17 PM
> > To: [email protected]
> > Subject: Re: [Wicket-user] Possible ListView Bug
> >
> >
> >
> >
> > why would it be if you ASK for the list through getList()
> > suddenly the model be set if at that time the model was empty
> > That is just strange/wrong.
> >
> > The contract of getList is just it will return a empty list if the model
> is null
> > so you don't have to test for null everytime you use getList.
> >
> > It is just for youre convinience.
> >
> >
> > On 9/15/05, Nick Heudecker <[EMAIL PROTECTED]> wrote:
> >
> > I believe it's a bug because it doesn't do what the user reasonably
> expects and it's not covered in the javadoc.
> >
> >
> >
> >
> >
> > On 9/15/05, Johan Compagner < [EMAIL PROTECTED]> wrote:
> >
> > why would that a bug?
> > it is just a check that getList() never returns null.
> >
> >
> >
> >
> >
> >
> >
> > On 9/15/05, Nick Heudecker <[EMAIL PROTECTED] > wrote:
> >
> > This looks like a bug to me.
> >
> > public final List getList()
> > {
> > final List list = (List)getModelObject();
> > if (list == null)
> > {
> > return Collections.EMPTY_LIST;
> > }
> > return list;
> > }
> >
> > The problem is if the model list is null, the Collections.EMPTY_LIST is
> returned but it's never set as the model object.
> >
> >
> >
> >
> >
> >
> >
> >
>
>
<!-- -------------------------------------------
Come visit us at:
Content Management Europe Exhibition. 29th November - 1st December 2005,
Olympia Grand Hall, London. Stand # 341
GOSS - Ranked 4th in the Deloitte Technology Fast 50 Awards 2004 and 88th in
the Deloitte Technology Fast 500 EMEA.
This email contains proprietary information, some or all of which may be
legally privileged. It is for the intended recipient only. If an addressing or
transmission error has misdirected this email, please notify the author by
replying to this email. If you are not the intended recipient you may not use,
disclose, distribute, copy, print or rely on this email.
Email transmission cannot be guaranteed to be secure or error free, as
information may be intercepted, corrupted, lost, destroyed, arrive late or
incomplete or contain viruses. This email and any files attached to it have
been checked with virus detection software before transmission. You should
nonetheless carry out your own virus check before opening any attachment. GOSS
Interactive Ltd accepts no liability for any loss or damage that may be caused
by software viruses.
-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user