Reputation: 4106
I know how to populate object with simple types (int, String) but how can I do this for a date value???
My class (called User
) has an attribute called date
of type java.util.Calendar
, is there any way to populate this field automatically on a html/jsp form?
My form:
Date: <input type="text" name="user.date">
Upvotes: 2
Views: 2426
Reputation: 371
<s:date name="user.date" format="MM/dd/yyyy" />
here the user.date is of Date type not checked with Calendar. please check
Upvotes: 1
Reputation: 23664
dates - uses the SHORT format for the Locale associated with the current request
Also take a look at the custom converter example
try and implement a custom converter
public class MyConverter extends StrutsTypeConverter {
public Object convertFromString(Map context, String[] values, Class toClass) {
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
Date date = sdf.parse(values[0]);
//do some validation on class and other stuff
}
public String convertToString(Map context, Object o) {
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
return sdf.format(o);
}
}
then register it with
user.date = com.xyz.MyConverter
in a properties file MyAction-conversion.properties
Upvotes: 2