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">
dates - uses the SHORT format for the Locale associated with the current request
struts2.0.14
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
<s:date name="user.date" format="MM/dd/yyyy" />
here the user.date is of Date type not checked with Calendar. please check
精彩评论