Re: looping on a list of lists (or accessing custom attributes of a list)

"Martin Cooper" <[email protected]>
Newsgroups gmane.comp.jakarta.taglibs.user
Message-ID <[email protected]>
On 6/3/06, Luca Passani <[email protected]> wrote:
>
>
> Hi guys, here is my big problem today.
>
> I have a list the items of two kinds (with and without icons) which gets
> turned into a list of lists.
>
> [x , x, y, x,y, y, y, y,x, x,y] becomes  [[x,x],[y],[x],[y,y,y,y],[x],[y]]
>
> When I render the list of lists in my JSP, I need to understand which
> kind of list it is I am dealing with.
> That's when I had a brilliant idea.


Hmm... ;-)

Two suggestions:

1) Instead of extending ArrayList, just encapsulate it. In other words, add
a property to LinkWithIconList for the list, so that you can access the list
explicitly using ${sub_list.list} or something. This seems like the simplest
approach.

2) The Unstandard taglib in the Taglibs sandbox has an 'instanceOf' tag that
might be useful to you.

--
Martin Cooper


I defined to subclasses of ArrayList:
>
> public class LinkWithIconList extends ArrayList {
>
>     public boolean isLinkWithIconList() {
>     return true;
>     }
>     public boolean isLinkWithoutIconList() {
>     return false;
>     }
> }
>
> (you can probably guess what the other class looks like :). And each
> sublist is an object of the respective subclasses.
> The rationale was to be able to do something like:
>
>
> <c:forEach var="sub_list" items="${list_of_lists}">
>   <c:choose>
>      <c:when test="${sub_list.linkWithIconList}">
>     render list with icons
>     </c:when>
>      <c:when test="${sub_list.linkWithoutIconList}">
>     render list without icons
>     </c:when>
>   </c:choose>
> </c:forEach>
>
> Unfortunately this doesn't work. ${sub_list.linkWithIconList} is
> interpreted as an attempt to access to an item of the collection (and
> not one of its properties):
>
> javax.servlet.ServletException: The "." operator was supplied with
> an index value of type "java.lang.String" to be
> applied to a List or array, but that value cannot be converted to an
> integer.
>
> So,  the question for this respactable forum is:
> - is there an easy way to achieve what I am trying to achieve?
> - are there other ways to achieve my goals?
>
> Thanks
>
> Luca
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.