You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by "Craig R. McClanahan" <Cr...@eng.sun.com> on 2001/03/05 03:59:15 UTC

Iterating over collections with null values

Bugzilla bug report #706 reports that you will get a JSP page exception
when you try to iterate over collection that contains null values.  This
is caused by the fact that the JSP page context refuses to allow null
attributes.  The bug report suggests one alternative (although the
proposed implementation has problems), but I would like to solicit
suggestions and thoughts on what the correct behavior should be.

Here are the alternatives that I can think of:

(1)  No change -- document a restriction in the usage notes
     on the <logic:iterate> tag.

(2)  Silently skip this element of the iteration, with no notice
     to the surrounding page.  The total number of times through
     the loop, from the perspective of the page, will be less than
     the size of the underlying collection.

(3)  Do not skip this element, but don't add it to the page context
     either.  The page can then use <logic:notPresent> to test for
     whether the item is actually there or not.

(4)  Do not skip this element, but insert a reference to a dummy
     object instead of the null.  This is likely to cause class cast
     exceptions, and is unlikely to be practical when the iteration
     explicitly includes a "type" attribute.

(5)  Other alternatives I have not thought of?

All of the listed alternatives have their problems, but I am currently
leaning towards (1).  Comments?  Suggestions?

Craig McClanahan



Re: Iterating over collections with null values

Posted by Elod Horvath <el...@itfais.com>.
Nick Pellow wrote:
> 
> "Craig R. McClanahan" wrote:
> >
> > Bugzilla bug report #706 reports that you will get a JSP page exception
> > when you try to iterate over collection that contains null values.  This
> > is caused by the fact that the JSP page context refuses to allow null
> > attributes.  The bug report suggests one alternative (although the
> > proposed implementation has problems), but I would like to solicit
> > suggestions and thoughts on what the correct behavior should be.
> >
> > Here are the alternatives that I can think of:
> >
> > (1)  No change -- document a restriction in the usage notes
> >      on the <logic:iterate> tag.
> >
> > (2)  Silently skip this element of the iteration, with no notice
> >      to the surrounding page.  The total number of times through
> >      the loop, from the perspective of the page, will be less than
> >      the size of the underlying collection.
> >
> > (3)  Do not skip this element, but don't add it to the page context
> >      either.  The page can then use <logic:notPresent> to test for
> >      whether the item is actually there or not.
> >
> > (4)  Do not skip this element, but insert a reference to a dummy
> >      object instead of the null.  This is likely to cause class cast
> >      exceptions, and is unlikely to be practical when the iteration
> >      explicitly includes a "type" attribute.
> >
>   (5) Add an attribute(s) on the iterate tag that allows the user to
> decide between (1), (2) and (3). Defaulting to (1).
> 


i like (5).  it leaves me options.  as a developer, i like options.
i don't like being dictated to [by a framework tool].  :)
i know it's more work for a committer, but...
(4) is definitely out.  

e
-- 
_______________________________________________________________________
Elod Horvath ('e')       /      ITFAIS Records (http://www.itfais.com/)

Re: Iterating over collections with null values

Posted by Nick Pellow <ni...@cortexebusiness.com.au>.

Martin Cooper wrote:
> 
> (1) This would be fine with me. Given that there seem to be as many opinions
> on this subject as people expressing them, perhaps this would be the
> expedient choice for 1.0.
> 
> (2) I don't like this because of the disparity between the number of
> iterations and the size of the collection. The <bean:size> tag becomes
> somewhat less useful.
> 
> (3) I believe this is the best of the "do something" options. It effectively
> documents the issue and provides a simple way of handling it.
> 
> (4) This sounds like a pretty bad idea. :-}
> 
> (5) I really don't like this. It makes me think of Perl's "There's More Than
> One Way To Do It" slogan. IMHO, having more options is not always better.

I was thinking (5) would allow struts to be used as easily as possible
with
an existing middle tier. However, the more I think about (5) the more it
seems
like the options could be misused to implement business logic. This is
definitely
not desired.
I don't like (2) or (3) for the same reason, so I am now leaning towards
(1).

Nick


> 
> --
> Martin Cooper
> 
> ----- Original Message -----
> From: "Nick Pellow" <ni...@cortexebusiness.com.au>
> To: <st...@jakarta.apache.org>
> Sent: Sunday, March 04, 2001 7:50 PM
> Subject: Re: Iterating over collections with null values
> 
> >
> >
> > "Craig R. McClanahan" wrote:
> > >
> > > Bugzilla bug report #706 reports that you will get a JSP page exception
> > > when you try to iterate over collection that contains null values.  This
> > > is caused by the fact that the JSP page context refuses to allow null
> > > attributes.  The bug report suggests one alternative (although the
> > > proposed implementation has problems), but I would like to solicit
> > > suggestions and thoughts on what the correct behavior should be.
> > >
> > > Here are the alternatives that I can think of:
> > >
> > > (1)  No change -- document a restriction in the usage notes
> > >      on the <logic:iterate> tag.
> > >
> > > (2)  Silently skip this element of the iteration, with no notice
> > >      to the surrounding page.  The total number of times through
> > >      the loop, from the perspective of the page, will be less than
> > >      the size of the underlying collection.
> > >
> > > (3)  Do not skip this element, but don't add it to the page context
> > >      either.  The page can then use <logic:notPresent> to test for
> > >      whether the item is actually there or not.
> > >
> > > (4)  Do not skip this element, but insert a reference to a dummy
> > >      object instead of the null.  This is likely to cause class cast
> > >      exceptions, and is unlikely to be practical when the iteration
> > >      explicitly includes a "type" attribute.
> > >
> > > (5)  Other alternatives I have not thought of?
> >
> >   (5) Add an attribute(s) on the iterate tag that allows the user to
> > decide between (1), (2) and (3). Defaulting to (1).
> >
> > >
> > > All of the listed alternatives have their problems, but I am currently
> > > leaning towards (1).  Comments?  Suggestions?
> > >
> > > Craig McClanahan

Re: Iterating over collections with null values

Posted by Martin Cooper <ma...@tumbleweed.com>.
(1) This would be fine with me. Given that there seem to be as many opinions
on this subject as people expressing them, perhaps this would be the
expedient choice for 1.0.

(2) I don't like this because of the disparity between the number of
iterations and the size of the collection. The <bean:size> tag becomes
somewhat less useful.

(3) I believe this is the best of the "do something" options. It effectively
documents the issue and provides a simple way of handling it.

(4) This sounds like a pretty bad idea. :-}

(5) I really don't like this. It makes me think of Perl's "There's More Than
One Way To Do It" slogan. IMHO, having more options is not always better.

--
Martin Cooper


----- Original Message -----
From: "Nick Pellow" <ni...@cortexebusiness.com.au>
To: <st...@jakarta.apache.org>
Sent: Sunday, March 04, 2001 7:50 PM
Subject: Re: Iterating over collections with null values


>
>
> "Craig R. McClanahan" wrote:
> >
> > Bugzilla bug report #706 reports that you will get a JSP page exception
> > when you try to iterate over collection that contains null values.  This
> > is caused by the fact that the JSP page context refuses to allow null
> > attributes.  The bug report suggests one alternative (although the
> > proposed implementation has problems), but I would like to solicit
> > suggestions and thoughts on what the correct behavior should be.
> >
> > Here are the alternatives that I can think of:
> >
> > (1)  No change -- document a restriction in the usage notes
> >      on the <logic:iterate> tag.
> >
> > (2)  Silently skip this element of the iteration, with no notice
> >      to the surrounding page.  The total number of times through
> >      the loop, from the perspective of the page, will be less than
> >      the size of the underlying collection.
> >
> > (3)  Do not skip this element, but don't add it to the page context
> >      either.  The page can then use <logic:notPresent> to test for
> >      whether the item is actually there or not.
> >
> > (4)  Do not skip this element, but insert a reference to a dummy
> >      object instead of the null.  This is likely to cause class cast
> >      exceptions, and is unlikely to be practical when the iteration
> >      explicitly includes a "type" attribute.
> >
> > (5)  Other alternatives I have not thought of?
>
>   (5) Add an attribute(s) on the iterate tag that allows the user to
> decide between (1), (2) and (3). Defaulting to (1).
>
> >
> > All of the listed alternatives have their problems, but I am currently
> > leaning towards (1).  Comments?  Suggestions?
> >
> > Craig McClanahan



Re: Iterating over collections with null values

Posted by Michael Gerdau <mg...@technosis.de>.
>> Here are the alternatives that I can think of:
[skipped for brevity]

>  (5) Add an attribute(s) on the iterate tag that allows the user to
>decide between (1), (2) and (3). Defaulting to (1).

I like that idea. Of course all possible behaviours should be selectable.

Also add
  (6) Add an optional attribute on the iterate tag that evaluates to a
      default object of the same type as the objects in the collection
      and which is taken when encountering a null value in the collection.

Best,
Michael
--
 Vote against SPAM - see http://www.politik-digital.de/spam/
 Michael Gerdau       email: mgd@technosis.de
 Windows is fne for Hih Sped Communicatns ...
 PGP-keys available on request or at public keyserver



Re: Iterating over collections with null values

Posted by Nick Pellow <ni...@cortexebusiness.com.au>.

"Craig R. McClanahan" wrote:
> 
> Bugzilla bug report #706 reports that you will get a JSP page exception
> when you try to iterate over collection that contains null values.  This
> is caused by the fact that the JSP page context refuses to allow null
> attributes.  The bug report suggests one alternative (although the
> proposed implementation has problems), but I would like to solicit
> suggestions and thoughts on what the correct behavior should be.
> 
> Here are the alternatives that I can think of:
> 
> (1)  No change -- document a restriction in the usage notes
>      on the <logic:iterate> tag.
> 
> (2)  Silently skip this element of the iteration, with no notice
>      to the surrounding page.  The total number of times through
>      the loop, from the perspective of the page, will be less than
>      the size of the underlying collection.
> 
> (3)  Do not skip this element, but don't add it to the page context
>      either.  The page can then use <logic:notPresent> to test for
>      whether the item is actually there or not.
> 
> (4)  Do not skip this element, but insert a reference to a dummy
>      object instead of the null.  This is likely to cause class cast
>      exceptions, and is unlikely to be practical when the iteration
>      explicitly includes a "type" attribute.
> 
> (5)  Other alternatives I have not thought of?

  (5) Add an attribute(s) on the iterate tag that allows the user to
decide between (1), (2) and (3). Defaulting to (1).

> 
> All of the listed alternatives have their problems, but I am currently
> leaning towards (1).  Comments?  Suggestions?
> 
> Craig McClanahan