0
Hello, I have the following method:
@RequestMapping(value = "/pesquisa", method = RequestMethod.POST)
public String pesquisa(@ModelAttribute("relSintetico") @Valid RelSintetico relSintetico, BindingResult bindingResult) {
Timestamp dataInicial = relSintetico.getDataInicial();
Timestamp dataFinal = relSintetico.getDataFinal();
System.out.println("Pesquisando");
System.out.println(dataInicial);
List<VE_RelResumoArrecadacao> relatorio = repositorioSintetico.findByDataOperacao(dataInicial, dataFinal);
System.out.println("Pesquisado!");
System.out.println(relatorio.size());
return "sintetico.relatorios.tiles";
}
Such method takes the "modelAtribute" relay from the page below:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
Relatório Sintético
This is the Relsintetico Model class:
package br.com.apasi.spring.dominios;
import java.io.Serializable; import java.sql.Timestamp;
import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table;
@Entity @Table(name = "Relsintetico", Catalog = "Pedagio", schema = "dbo") public class Relsintetico Serializable Mplements {
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@Column(name = "IdRelSintetico")
private Integer idRelSintetico;
@Column(name = "DataInicial")
private Timestamp dataInicial;
@Column(name = "DataFinal")
private Timestamp dataFinal;
public Integer getIdRelSintetico() {
return idRelSintetico;
}
public void setIdRelSintetico(Integer idRelSintetico) {
this.idRelSintetico = idRelSintetico;
}
public Timestamp getDataInicial() {
return dataInicial;
}
public Timestamp getDataFinal() {
return dataFinal;
}
public void setDataInicial(Timestamp dataInicial) {
this.dataInicial = dataInicial;
}
public void setDataFinal(Timestamp dataFinal) {
this.dataFinal = dataFinal;
}
}
But the method returns null for getDataInitial and getDataFinal... Is it something to do with data conversion? or am I taking this data from the Model wrong?
Still Returns null in variables :(
– Fábio Luiz Schmidt de Oliveira
Put the JSP where the form is... In my project it is mapped as java.util.Date, it can be that too... I re-edited the answer, see if it works now...
– s_bighead
<c:url var="actionPsearch" value="/reports/search"></c:url> <div> <form:form action="${actionPesquisar}" modelAttribute="relSintetico" method="post"> <div class="Row"> <div class="col-Md-6"> <div class="form-group"> <form:input path="startData" type="date" cssClass="form-control" /> </div> </div> </div> <div class="Row"> <div class="col-Md-6"> <div class="form-group"> <form:input path="dataFinal" type="date" cssClass="form-control" />
– Fábio Luiz Schmidt de Oliveira
I switched to Date and still comes as null
– Fábio Luiz Schmidt de Oliveira
Tenta colocar o objeto no ModelAndView antes de carregar a página, tipo: ModelAndView modelAndView = new ModelAndView("viewName"); modelAndView.addObject("relSintetico", new RelSintetico()); no mais não vejo porque não está funcionando...
– s_bighead
this type="date" tag does not exist in <form:input> To trying to solve this problem.
– Fábio Luiz Schmidt de Oliveira
God right buddy... No more return with value Null, what you said was right, the problem is that I did not erase the get and set with Timestamp kkkk Valew
– Fábio Luiz Schmidt de Oliveira