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


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 

1 Answers

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());


<c:forEach items="${labelDTO.labelItemDTOS}" var="labelItemDTO">

Or for POST see this question possible the same issue.