I was reading a lot but I don't know what is the error in my code. I hope you can help me. Regards.
Model: RenglonFacturaDTO(With his getters/setters)
public class RenglonFacturaDTO implements Comparable<RenglonFacturaDTO>{
private Integer idfact;
private Long idrenglon;
private Integer idremito;
private Float cant;
private String descripadic;
private Double precio;
private Double subtotal;
}
This is the list of objects that i send via ajax to controller
<script>
$(document).ready(function(){
var cliente = $('.id').data('id');
var token = $("meta[name='_csrf']").attr("content");
var header = $("meta[name='_csrf_header']").attr("content");
var listado = [{}];
$('#generar').click(function(){
cliente = $('#idcliente').data('id');
$('.renglon').each(function(){
elem = $(this);
cant = elem.find('.cant').val();
precio = elem.find('.precio').val();
descripadic = elem.find('.descripadic').val();
idremito = elem.find('.idremito').text();
idrenglon = elem.data('idrenglon');
idfact = $('#factura').data('idfact');
subtotal = cant * precio;
listado.push({"cant": parseFloat(cant),"precio": precio ,"descripadic":descripadic,"subtotal":subtotal ,"idremito":idremito ,"idrenglon":idrenglon , "idfact":idfact});
});
$.ajax({
"type":"post",
"url":"agregarRenglonesFactura",
"dataType": 'json',
"cache": false,
"data": {"listado": listado},
beforeSend: function(xhr) {
// here it is
xhr.setRequestHeader(header, token);
}
});
});
});
</script>
Controller
@RequestMapping(value="/agregarRenglonesFactura", method= RequestMethod.POST)
public String redAgregarRenglonFactura(@ModelAttribute ArrayList<RenglonFacturaDTO> renglonesfacturadto) throws Exception{
Iterator<RenglonFacturaDTO> it = renglonesfacturadto.iterator();
while(it.hasNext()){
RenglonFacturaDTO renglonfacturadto = it.next();
System.out.println("***************AGREGAR RENGLON*******************IDRENGLONREMITO: " + renglonfacturadto.getIdrenglon() + " CANTIDAD: " + renglonfacturadto.getCant());
}
return ("TAMAÑO LISTA: " + renglonesfacturadto.size());
}
this is the error:
Request processing failed; nested exception is org.springframework.beans.InvalidPropertyException:
Invalid property 'listado[10][cant]' of bean class [ar.edu.grupoesfera.cursospring.modelo.ListadoRenglonesFacturaDTO]:
Property referenced in indexed property path 'listado[10][cant]' is neither an array nor a List nor a Map; returned value was [ar.edu.grupoesfera.cursospring.modelo.RenglonFacturaDTO@67e12cdf]] con causa raíz
This is the array that i send via post
listado[0][cant]15
listado[0][descripadic]
listado[0][idfact]12
listado[0][idremito]9
listado[0][idrenglon]36
listado[0][precio]135
listado[0][subtotal]2025
listado[1][cant]15
listado[1][descripadic]
listado[1][idfact]12
listado[1][idremito]9l
istado[1][idrenglon]36
listado[1][precio]135
listado[1][subtotal]2025
listado[2][cant]15
listado[2][descripadic]
listado[2][idfact]12
listado[2][idremito]9
listado[2][idrenglon]36
listado[2][precio]135
listado[2][subtotal]2025