Announcement Announcement Module
Collapse
No announcement yet.
IndexOutOfBounds on list of sub-items Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • IndexOutOfBounds on list of sub-items

    Hi, I've been getting an IndexOutOfBoundException on accessing a collection in one of my form beans.


    The formbean is about this:
    class Provider {
    ...
    private List contacts = new ArrayList(...);
    ... then getter and setter (getContacts() and setContacts(List)
    }



    The JSP is:
    <c:forEach items="${provider.contacts}" var="contact" varStatus="loopStatus">
    <tr>
    <td nowrap><b>Contact Name: </b></td>
    <spring:bind path="provider.contacts[${loopStatus.index}].name">
    <td><input type="text" name="<c:out value="${status.expression}"/>" value="<c:out value="${status.value}"/>"/></td>
    <c:if test="${status.error}">
    <c:forEach items="${status.errorMessages}" var="error">
    <td><font color="red"><c:out value="${error}"/></font></td>
    </c:forEach>
    </c:if>
    </spring:bind>
    </tr>



    The curious part is that if I replace that piece of the JSP by the below, it works.

    <b><br/><c:out value="${fn:length(provider.contacts)}"/> contacts for this provider</b>
    <c:out value="${provider.contacts[0].name}" />




    Any ideas of what I might be doing wrong?


    Thanks,

    Gustavo Hexsel

  • #2
    Exception stack trace

    I'm using JDK 1.5 + Spring 1.2. The exception goes below (sorry, I forgot earlier):

    org.springframework.beans.InvalidPropertyException : Invalid property 'contacts[0]' of bean class [com.sagebrushcorp.oberon.dataobject.Provider]: Index of out of bounds in property path 'contacts[0]'; nested exception is java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    org.springframework.beans.BeanWrapperImpl.getPrope rtyValue(BeanWrapperImpl.java:697)
    org.springframework.beans.BeanWrapperImpl.getNeste dBeanWrapper(BeanWrapperImpl.java:535)
    org.springframework.beans.BeanWrapperImpl.getBeanW rapperForPropertyPath(BeanWrapperImpl.java:513)
    org.springframework.beans.BeanWrapperImpl.getPrope rtyValue(BeanWrapperImpl.java:624)
    org.springframework.validation.BindException.getFi eldValue(BindException.java:333)
    org.springframework.web.servlet.support.BindStatus .<init>(BindStatus.java:117)
    org.springframework.web.servlet.tags.BindTag.doSta rtTagInternal(BindTag.java:115)
    org.springframework.web.servlet.tags.RequestContex tAwareTag.doStartTag(RequestContextAwareTag.java:6 8)
    org.apache.jsp.WEB_002dINF.jsp.edit_provider_jsp._ jspService(org.apache.jsp.WEB_002dINF.jsp.edit_pro vider_jsp:220)
    org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:99)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:325)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:295)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:245)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
    org.springframework.web.servlet.view.InternalResou rceView.renderMergedOutputModel(InternalResourceVi ew.java:97)
    org.springframework.web.servlet.view.AbstractView. render(AbstractView.java:250)
    org.springframework.web.servlet.DispatcherServlet. render(DispatcherServlet.java:928)
    org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:705)
    org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:625)
    org.springframework.web.servlet.FrameworkServlet.s erviceWrapper(FrameworkServlet.java:386)
    org.springframework.web.servlet.FrameworkServlet.d oGet(FrameworkServlet.java:346)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:689)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:802)

    Comment


    • #3
      Nevermind, I've found it... I was using an AbstractFormController and setting the commandName, and that was causing my manually set bean to be overwritten.

      Comment

      Working...
      X