Results 1 to 7 of 7
  1. #1
    chester_perry is offline Member
    Join Date
    Jan 2011
    Posts
    3
    Rep Power
    0

    Default JSTL accessing properties on an object that extends ArrayList

    I have an object that extends ArrayList and adds a bunch of properties (like title).

    When I do this

    <c:forEach items="${linkSet}" var="link" varStatus="status">

    ${linkSet.title}

    </c:forEach>

    I get this error :

    <Error 500: 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.

    Which implies that JSTL is treating "title" as an index value to get a value from the List - i.e. it's treating my extended List object as a simple List object.

    Is there anyway to get JSTL to see it as a property on an the extended List object and not an index on the underlying List class ?

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,863
    Rep Power
    19

    Default

    Not too sure extending ArrayList is the right idea, though I agree that it does appear that . is acting like [] here, which I hadn't noticed before.

    My suggestion is that your extended class should actually have an ArrayList as an attribute, and not extend ArrayList.

  3. #3
    chester_perry is offline Member
    Join Date
    Jan 2011
    Posts
    3
    Rep Power
    0

    Default

    Well, yes, I had thought of that. Except that this is an old and large code base being extended. This class is used all over the place, so re-factoring is not a small thing to do... was hoping to avoid that.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,863
    Rep Power
    19

    Default

    Ah, an old mistake.

    So this is just a new JSP then?
    Could you wrap the extended List into another object at the start of the JSP (with a note)?

  5. #5
    chester_perry is offline Member
    Join Date
    Jan 2011
    Posts
    3
    Rep Power
    0

    Default

    That might do it I guess. I have a slightly ugly fix using in-line Java (grabbing the object from the pageContext). I'll consider re-factoring if there is more work in this code base. However, I still think the JSTL behaviour is not what I would expect to see.

  6. #6
    muscat is offline Banned
    Join Date
    Jul 2013
    Posts
    1
    Rep Power
    0

    Default Re: JSTL accessing properties on an object that extends ArrayList

    Quote Originally Posted by chester_perry View Post
    I have an object that extends ArrayList and adds a bunch of properties (like title).

    When I do this

    <c:forEach items="${linkSet}" var="link" varStatus="status">

    ${linkSet.title}

    </c:forEach>

    I get this error :

    <Error 500: 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.

    Which implies that JSTL is treating "title" as an index value to get a value from the List - i.e. it's treating my extended List object as a simple List object.

    Is there anyway to get JSTL to see it as a property on an the extended List object and not an index on the underlying List class ?
    In your java code don't return an object list declared locally
    example
    public list getmyList()
    {
    list totolist;
    totolist = callAnotherList();
    return totolist;
    }
    do insead:
    public list getmyList()
    {
    return callAnotherList();
    }

    Worked fine for me.

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default Re: JSTL accessing properties on an object that extends ArrayList

    Please don't post to long dead threads.

    db

    THREAD CLOSED
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Iterate over Map object using JSTL
    By syncFool in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 10-21-2010, 06:25 AM
  2. Replies: 5
    Last Post: 05-17-2010, 01:13 PM
  3. Accessing Properties File
    By java_men in forum Java Servlet
    Replies: 0
    Last Post: 05-11-2010, 11:34 AM
  4. Replies: 3
    Last Post: 03-15-2010, 08:44 PM
  5. Accessing to file roots and their properties
    By JVega in forum Advanced Java
    Replies: 3
    Last Post: 01-25-2010, 12:25 PM

Tags for this Thread

Posting Permissions

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