@RequestParam("cid") String cid,
@ModelAttribute("emailForm") EmailForm emailForm,
BindingResult result,
HttpServletRequest request) throws Exception {
ZeroView view = new ZeroView(getMessages(), request.getLocale());
if (validate(new EmailValidator(), emailForm, result, view)) {
EmailWidget widget = (EmailWidget) getWidgetManager(session).getWidget(cid);
widget.setSender(emailForm.getSender());
widget.setMessage(emailForm.getMessage());
widget.setSubject(emailForm.getSubject());
int count = 0;
for (String receiver : widget.getReceivers()) {
Email email = new Email();
email.setSender(emailForm.getSender());
email.setRecepient(receiver);
email.setMsgText(emailForm.getMessage());
email.setSubject(emailForm.getSubject());
email.setReferenceType(widget.getReferenceType());
email.setReferenceId(widget.getReferenceId());
emailDao.makePersistent(email);
count ++;
}
view.setMessage(new Message("base.email.added", Message.MSG_INFO, Integer.toString(count)));
}
return new ModelAndView(view, null);
}