}
@Override
public void readForm(PageRecurrenceForm form, ActionMessages errors, HttpServletRequest request)
{
EventVO event = (EventVO) getPanel().getEntity();
EventVO.RecurrenceType type = EnumUtility.valueOf(EventVO.RecurrenceType.class, form.getRecurrenceType());
if(!form.isRecurrence())
{
event.setRecurrenceType(EventVO.RecurrenceType.NONE);
event.setRecurrenceNumberOfTimes(null);
event.setRecurrenceUntilDate(null);
event.setRecurrenceCycle(null);
event.setRecurrenceCycleUnit(null);
event.setRecurrenceInMonth(null);
event.getRecurrenceInWeek().clear();
}
else
{
event.setRecurrenceType(EnumUtility.valueOf(EventVO.RecurrenceType.class, form.getRecurrenceType()));
if(type.equals(EventVO.RecurrenceType.NUMBER_OF_TIMES))
{
event.setRecurrenceNumberOfTimes(form.getNumberOfTimes());
event.setRecurrenceUntilDate(null);
}
else if(type.equals(EventVO.RecurrenceType.UNTIL_DATE))
{
try
{
SimpleDateFormat sdf = new SimpleDateFormat(MessageUtil.message(request, "default.format.input.date"));
Calendar cal = GregorianCalendar.getInstance();
cal.setTime(sdf.parse(form.getUntilDate()));
cal.add(Calendar.DAY_OF_YEAR, 1);
cal.add(Calendar.MILLISECOND, -1);
event.setRecurrenceUntilDate(cal.getTime());
}
catch (ParseException e)
{
log.error("problems parsing recurrence until date", e);
}
event.setRecurrenceNumberOfTimes(null);
}
else if(type.equals(EventVO.RecurrenceType.FOREVER))
{
event.setRecurrenceNumberOfTimes(null);
event.setRecurrenceUntilDate(null);
}
event.setRecurrenceCycle(form.getCycle());
event.setRecurrenceCycleUnit(EnumUtility.valueOf(EventVO.RecurrenceUnit.class, form.getCycleUnit()));
if(EventVO.RecurrenceUnit.WEEK.equals(event.getRecurrenceCycleUnit()))
{
event.getRecurrenceInWeek().clear();
for(int i=0; i<form.getInWeek().length; i++)
event.getRecurrenceInWeek().add(EnumUtility.valueOf(EventVO.RecurrenceInWeek.class, form.getInWeek()[i]));
event.setRecurrenceInMonth(null);
}
else if(EventVO.RecurrenceUnit.MONTH.equals(event.getRecurrenceCycleUnit()))
{
event.setRecurrenceInMonth(EnumUtility.valueOf(EventVO.RecurrenceInMonth.class, form.getInMonth()));
event.getRecurrenceInWeek().clear();
}
}
}