Announcement Announcement Module
Collapse
No announcement yet.
help - spring:bind error while using java.util.Set Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • help - spring:bind error while using java.util.Set

    Hi,
    I am getting the following error while saving my form :

    org.springframework.beans.InvalidPropertyException : Invalid property 'timeEntryList[0]' of bean class [com.msdw.pbefficiency.servicestracker.hibernate.po jo.TimeSheet]: Cannot get element with index 0 from Set of size 0, accessed using property path 'timeEntryList[0]'
    org.springframework.beans.BeanWrapperImpl.getPrope rtyValue(BeanWrapperImpl.java:563)
    org.springframework.beans.BeanWrapperImpl.getNeste dBeanWrapper(BeanWrapperImpl.java:441)
    org.springframework.beans.BeanWrapperImpl.getBeanW rapperForPropertyPath(BeanWrapperImpl.java:418)
    org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:635)
    org.springframework.beans.AbstractPropertyAccessor .setPropertyValues(AbstractPropertyAccessor.java:7 8)
    org.springframework.validation.DataBinder.applyPro pertyValues(DataBinder.java:532)
    org.springframework.validation.DataBinder.doBind(D ataBinder.java:434)
    org.springframework.web.bind.WebDataBinder.doBind( WebDataBinder.java:147)
    org.springframework.web.bind.ServletRequestDataBin der.bind(ServletRequestDataBinder.java:108)

    My Command class is TimeSheet which has a Set of timeEntry objects. While rendering the form the values are printed fine. While calling submit the above mentioned error occurs. The call does not reach the onSubmit method at all.

    My jsp snippet is :

    <spring:bind path="timeSheet.timeSheetId">
    <input type="hidden" name="${status.expression}" value="${status.value}" />
    </spring:bind>
    <tr><td colspan="21" class="hRule">&nbsp;</td></tr>
    <c:forEach items="${timeSheet.timeEntryList}" var="timeEntry" varStatus="timeEntryRow">
    <spring:bind path="timeSheet.timeEntryList[${timeEntryRow.index}].timeEntryId">
    <input type="hidden" name="${status.expression}" value="${status.value}" />
    </spring:bind>
    </c:forEach>

    Someone please assist

  • #2
    You can only bind to an indexed collection, which is a List implementation. Set isn't indexed and this cannot be binded to...

    Comment


    • #3
      thanks for your reply. i figured that one out and have changed all the sets to lists. also had to change a lot on the hibernate side. it seems even with lists there is a problem and we need to use LazyList. used tips from the following :

      http://mattfleming.com/node/134

      Comment


      • #4
        Originally posted by Marten Deinum View Post
        You can only bind to an indexed collection, which is a List implementation. Set isn't indexed and this cannot be binded to...
        Thank you, thank you, thank you! My JPA entity had a Set property with an @Valid annotation, and upon validation, this exception was thrown:

        Code:
        Invalid index in property path 'foos[]'; nested exception is java.lang.NumberFormatException: For input string: ""
        I added a getter that wrapped the Set in a List, moved the annotation to that getter, and problem solved.

        Comment

        Working...
        X