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

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

    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(
    org.springframework.beans.BeanWrapperImpl.getNeste dBeanWrapper(
    org.springframework.beans.BeanWrapperImpl.getBeanW rapperForPropertyPath(
    org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(
    org.springframework.beans.AbstractPropertyAccessor .setPropertyValues( 8)
    org.springframework.validation.DataBinder.applyPro pertyValues(
    org.springframework.web.bind.ServletRequestDataBin der.bind(

    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}" />
    <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}" />

    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...


    • #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 :


      • #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:

        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.