I am trying to bing List of Lists in spring MVC is it possible? Do we need to write any custom binding methods? Please help me.

JSTL Code :

 <input id="labelDTOS0.labelItemDTOS0.newValue" 
 name="labelDTOS[0].labelItemDTOS[0].newValue" type="text" value=""/>

DTOs:

public class LabelDTO {
public long id;
public String name;
public List<LabelItemDTO> labelItemDTOS;
}

public class LabelItemDTO {
public String value;
public String placeHolder;
public String newValue;
}

Exception :

Invalid property 'labelDTOS[0].labelItemDTOS[0]' of bean class 
[com.goitdev.datarender.command.domain.CreateTemplateCommand]: Illegal 
attempt to get property 'labelItemDTOS' threw exception; nested exception 
is org.springframework.beans.NullValueInNestedPathException: Invalid 
property 'labelDTOS[0].labelItemDTOS' of bean class 
[com.goitdev.datarender.command.domain.CreateTemplateCommand]: Could not 
instantiate property type [com.goitdev.datarender.dto.domain.LabelItemDTO] 
to auto-grow nested property path; nested exception is 
java.lang.NoSuchMethodException: 
com.goitdev.datarender.dto.domain.LabelItemDTO.<init>()

1 Answers

1
A.Kiselev On

If you try to perform GET mapping and print out value of your DTO, you can try this:
In your controller method:

...
model.addAttribute("labelDTO", new LabelDTO());
...

In JSP

...
<c:forEach items="${labelDTO.labelItemDTOS}" var="labelItemDTO">
<td>${labelItemDTO.value}<td>
<td>${labelItemDTO.placeHolder}<td>
<td>${labelItemDTO.newValue}<td>
</c:forEach>
...

Or for POST see this question possible the same issue.