Results 1 to 5 of 5

Thread: Error while accessing collections

  1. #1
    Join Date
    Nov 2005
    Posts
    8

    Default Error while accessing collections

    This is an intermittent problem for the same record set, here is the error I am getting:

    Code:
    org.springframework.beans.InvalidPropertyException: Invalid 
    property 'alternateResources[0]' of bean class [xxx.vo.ScreenProposalMaterialVO]: 
    Index of out of bounds in property path 'alternateResources[0]'; nested exception is 
    java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    	at java.util.ArrayList.RangeCheck(ArrayList.java:546)
    	at java.util.ArrayList.get(ArrayList.java:321)
    	at org.springframework.beans.BeanWrapperImpl.getPropertyValue
    (BeanWrapperImpl.java:408)
    	at org.springframework.beans.BeanWrapperImpl.getNestedBeanWrapper(BeanWrapperImpl.java:297)
    	at org.springframework.beans.BeanWrapperImpl.getBeanWrapperForPropertyPath(BeanWrapperImpl.java:274)
    and below is code which is causing this:
    Code:
    <c:forEach var="resourceEntry" 
    items="${command.alternateResources}"
    varStatus="lineInfo">
    .....................
    <spring:bind path="command.alternateResources[${lineInfo.index}].price">
    ....................
    Any ideas? If the collection is empty, it should go into foreach block only but from the debugging it is clear that the collection is having its associated values but it fails when it encounters the spring bind.

  2. #2
    Join Date
    Nov 2005
    Posts
    8

    Default

    Just to make sure it is not a JSTL issue, I did added additional test though it is not required:
    <c:if test="${not empty command.alternateResources}">
    before the foreach.

    Again, as I said, it is intermittent, we get this once in a while.

    Your help is highly appreciated.

    Thanks,
    Arshad

  3. #3
    Join Date
    Nov 2005
    Posts
    8

    Default

    Here is what we followed:
    http://opensource.atlassian.com/proj.../browse/SPR-52

    and the example is:
    Code:
    <c:forEach items="${person.addresses}" var="address" varStatus="loopStatus">
    
    <spring:bind path="person.addresses[${loopStatus.index}].street">
    Street: <input type="text" name="<%= status.getExpression() %>" value="<%= status.getDisplayValue() %>">
    </spring:bind>
    <p>
    
    <spring:bind path="person.addresses[${loopStatus.index}].zip">
    Zip: <input type="text" name="<%= status.getExpression() %>" value="<%= status.getValue() %>">
    </spring:bind>
    <p>
    
    </c:forEach>
    and the code is from Juergen Hoeller who is spring team member I belive. What I can say is the code is correct syntactical from spring point of view but gives errors intermittently at runtime

    Thanks,
    Arshad

  4. #4
    Join Date
    Nov 2005
    Location
    Reutlingen, Germany
    Posts
    2,098

    Default

    Is this still the actual situation? It's absolutely awkward to use and understand. Furthermore it does not work with non-indexed collections. Why must <spring:bind> always traverse from the command object (absolute context) and does not allow a relative context? So in a loop it would be easily possible to set that context and <spring:bind> would use that one:

    Code:
    <c:forEach items="${collection}" var="collEntry">
      <spring:newPath path="collEntry">
        <tr>
          <td>
            <spring:bind path="collEntry.key">${status.value}</spring:bind>
          </td>
          <td>
            <spring:bind path="collEntry.value">${status.value}</spring:bind>
          </td>
        </tr>
      </spring:newPath>
    </c:forEach>
    This would make it usable for non-indexed collections and more readable and less error-prone in general. It would not break the default concept of <c:forEach> and match similar concepts in XSLT (or XML/XPath in general).

    Jörg

  5. #5
    Join Date
    Nov 2005
    Location
    Reutlingen, Germany
    Posts
    2,098

    Default

    For the records: I added a Jira enhancement request for it.

    Jörg

Posting Permissions

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