}
public HttpResponse vote(HttpRequest request, Long poll_id) throws HttpException {
Poll p = javango.getObjectOr404(Poll.class, poll_id);
VoteForm form = javango.newForm(VoteForm.class).setPoll(p);
form.bind(request.getParameterMap());
if (!form.isValid()) {
Map<String, Object> context = new HashMap<String, Object>();
context.put("poll", p);
context.put("error_message", "You didn't select a valid choice");
context.put("form", form);
return renderToResponse("javango/polls/templates/detail.ftl", context);
}
Choice selected_choice = (Choice)form.getCleanedValue(form.choice);
int votes = selected_choice.getVotes() == null ? 0 : selected_choice.getVotes().intValue();
selected_choice.setVotes(votes + 1);
// due to the way hibernate works this will automatically save when the middleware commits
return new HttpResponseRedirect("/polls/" + poll_id + "/results/");