Announcement Announcement Module
Collapse
No announcement yet.
No way to bind an indexed property with primitive elements. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • No way to bind an indexed property with primitive elements.

    Spring Framework 3.1.1.RELEASE.
    I fail to successfully bind the contents of a list of primitive types (their wrappers actually).

    Model bean:
    Code:
     class Bean {
       private List<Double> elements;
    
       public List<Double> getElements() {
         if (elements == null)
           elements = new ArrayList<>();
         return elements;
       }
       public void setElements(List<Double> elements) {
         this.elements = elements;
       }
    
       public Double getElement(int pos) {
         if (elements == null || elements.size() <= pos)
           return null;
         return elements.get(pos);
       }
       public void setElement(int pos, Double element) {
         if (elements == null)
           elements = new ArrayList<>(pos+1);
         while (elements.size() < pos + 1)
           elements.add(null);
         elements.set(pos, element);
       }
     }
    I tried the following configurations (FreeMarker view), but none worked:
    Code:
     <@s.bind "bean.elements(0)"/>
     <@s.bind "bean.elements[0]"/>
     <@s.bind "bean.element(0)"/>
     <@s.bind "bean.element[0]"/>
    I get any of the following:
    Code:
     org.springframework.beans.NullValueInNestedPathException: Invalid property 'elements' of bean class [com.company.Bean]: Could not instantiate property type [java.lang.Double] to auto-grow nested property path: java.lang.InstantiationException: java.lang.Double
    
     org.springframework.beans.InvalidPropertyException: Invalid property 'elements[0]' of bean class [com.company.Bean]: Illegal attempt to get property 'prices' threw exception; nested exception is org.springframework.beans.NullValueInNestedPathException: Invalid property 'elements' of bean class [com.company.Bean]: Could not instantiate property type [java.lang.Double] to auto-grow nested property path: java.lang.InstantiationException: java.lang.Double
    What is the proper way to bind collections of primitives in Spring Web MVC?
    Any resources I can find only deal with collections of beans, which DOES NOT work for me!
Working...
X