0

I am facing currently a huge issue : I can not retrieve date input by user in JSP page.

JSP code :

<form:form method="POST" action="myAction"> 
<tr><td>Date</td>
<td>
<spring:nestedPath path="myClasse.startDate" >
<input type="text" name="startDate" value="<c:out value="${status.value}"/> "/></spring:nestedPath>
</td></tr>

I input date in all existing forms. my code part corresponding to the retrieval of startDate in the Controller:

System.out.println("date: " + myClasse.getStartDate());

give me null

Here are some details that can help :

I have this in my model class :

@Temporal(TemporalType.TIMESTAMP)
@Column(name = "start_date", length = 19)
public Date getStartDate()
{
    return this.startDate;
}

public void setStartDate(Date startDate)
{
    this.startDate = startDate;
}

Service class :

session.createQuery("SELECT DISTINCT name where startDate=:startDate").setParameter("startDate", "startDate");
4

1 回答 1

1

我找到了可以解决此问题的解决方案:

在我的控制器类中,我添加了这个:

 @InitBinder
 public void initBinder(WebDataBinder binder)
 {
  SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  dateFormat.setLenient(false);
  binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
 }

希望这将帮助面临这个问题的人:)

于 2013-07-09T08:06:01.050 回答