Results 1 to 3 of 3

Thread: jsp 2.0 Tag File Attribute Question

  1. #1
    Join Date
    Oct 2005
    Location
    Mobile, AL
    Posts
    345

    Default jsp 2.0 Tag File Attribute Question

    I am trying to pass a List of objects as a attribute to a custom tag file. The problem is that it looks like the collection that the tag file gets is now a List of String objects! From what I can tell, it is calling the toString method on my object class and converting each of the objects to a String.

    Does anyone have any ideas on how I can successfully reference a list of objects from within a jsp 2.0 Tag File?

    FYI: I am passing other attributes as well that are not collections and they work as expected.

    Any Help would be appreciated.

    Thanks,

    Marty

  2. #2
    Join Date
    Oct 2005
    Location
    Mobile, AL
    Posts
    345

    Default Update

    I created a wrapper class to hold the List and then specified the class as the "type" argument for the tag file attribute and the collection works as expected. This seems like a lot of work to have to wrap collections in order for the jsp 2.0 attribute to not convert my objects to strings.

    Hopefully someone else has run into this and has a more elegant solution.

    Marty

  3. #3
    Join Date
    Aug 2011
    Posts
    1

    Default iterating through lists in jsp 2.0 tag files

    Use the dynamic-attributes attribute of the tag. In this example, the list is stored in an "items" attribute passed in:

    <%@ tag dynamic-attributes="dynattrs"%>

    <c:forEach items="${dynattrs.items}" var="dm">
    <span>${dm.key} = ${dm.value}</span>
    </c:forEach>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •