Dmitry Dmitry - 9 months ago 97
Java Question

Processing Date in Struts 1 ActionForm

I have problem on processing input request parameter (of course it's type String) to

. I thought that following code added to my bean might solve this problem, but I was wrong:

public Date getDate() {
return date;

public void setDate(Date date) { = date;

public void setDate(String dateString) {
try {
date = DateFormat.getDateInstance().parse(dateString);
} catch (ParseException e) {
date = new Date();

It throws an exception after submiting form:

javax.servlet.ServletException: BeanUtils.populate

java.lang.IllegalArgumentException: Cannot invoke com.epam.testapp.model.News.setDate - argument type mismatch

Is this fundamental of struts 1 form that this code won't work because of mismatch of returning getter and accepting setter parameter types? How can I solve this problem ? I don't want at all to make method named like
setStringDate(String stringDate(){...}
and think on every page which method should I call :(


Date object cannot be a property in struts as date format can vary (depending on specification). Some may have dd-MM-yyyy, dd-MMMM-yy, etc.

I would suggest having a property:

private String date;

public String getDate() { return date; }

public void setDate(String date) { = date; }

And in your action, convert the date string into Date object.