formshibernatestruts2submitaction

Struts 2 - Date instance become String


When I submit the form, input error is occured. JourneyDate is an instance of 'Date'. But, here it become String, which is not accepted by the setter and getter.

<s:hidden name="JourneyDate" value="%{JourneyDate}"></s:hidden>

I want JourneyPlan as Date type, but it becomes a String.


Solution

  • Try intercepting the value before passing it to the getter/setter. For example send JourneyDateString from your form, create a Date from the String, and then pass that to your getter/setter. Something like:

    public void setJourneyDateString(String journeyDateString)
    {
         //journeyDateString could be "2013-03-28" for example
         Date journeyDate = new SimpleDateFormat("yyyy-MM-dd").parse(journeyDateString);
         setJourneyDate(journeyDate);
    }