With an action as follows :-
public class MyAction extends ActionSupport {
...
private List<LocalDate> selectedPurchasePeriods = new ArrayList();
...
public void setSelectedPurChasePeriodes(List<LocalDate> periods) {
this.selectedPurchasePeriods = periods;
}
....
}
To allow conversion to take place, we probably needs to write up a converter, such that when a requiest such as
will results in the List<LocalDate> being populated with 2 dates.
Here's how the converter might look like (notes are inserted as comments in the code)
/**
* @author martin.gilday
*
*/
public class YearMonthToLocalDateConverter extends WebWorkTypeConverter {
private Logger log = Logger.getLogger(YearMonthToLocalDateConverter.class);
private static final DateTimeFormatter YEAR_MONTH_FORMAT = DateTimeFormat.forPattern("yyyy-MM");
@Override
public Object convertFromString(Map context, String[] values, Class toClass) {
try {
return new ArrayList() {
{
add(YEAR_MONTH_FORMAT.parseDateTime(values[0]).toLocalDate());
add(YEAR_MONTH_FORMAT.parseDateTime(values[1]).toLocalDate());
}
};
} catch (Exception e) {
log.error("FAILURE TO CONVERT", e);
throw new TypeConversionException("Unable to convert to LocalDate");
}
}
@Override
public String convertToString(Map context, Object o) {
try {
....
} catch (Exception e) {
throw new TypeConversionException("Unable to convert LocalDate to String");
}
}
}
 |
WebWork uses request.getParameterValues(...) when getting request parameters, and the converter could access it using values[0], values[1] .... etc |