Package javango.polls.forms

Examples of javango.polls.forms.VoteForm


  }
 
  public HttpResponse detail(HttpRequest request, Long poll_id) throws HttpException {
    Poll p = javango.getObjectOr404(Poll.class,poll_id);
   
    VoteForm form = javango.newForm(VoteForm.class).setPoll(p);
   
    Map<String, Object> context = new HashMap<String, Object>();
    context.put("poll", p);
    context.put("form", form);
                 
View Full Code Here


  }
 
  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/");
View Full Code Here

      Poll p = modelFactory.dao(Poll.class).get(poll_id);
      if (p == null) {
        return new SimpleHttpResponse("Unable to find poll with id = " + poll_id);
      }
     
      VoteForm form = (VoteForm)formFactory.newForm(VoteForm.class);
      form.updateChoices(p);
     
      Map<String, Object> context = new HashMap<String, Object>();
      context.put("poll", p);
      context.put("form", form);
                   
View Full Code Here

 
  public HttpResponse vote(HttpRequest request, Long poll_id) throws HttpException {
    try {
      Poll p = modelFactory.dao(Poll.class).get(poll_id);
     
      VoteForm form = (VoteForm)formFactory.newForm(VoteForm.class).bind(request.getParameterMap());
      form.updateChoices(p);
     
      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("src/main/webapp/templates/detail.html", context);
      }
     
      Long choice = (Long)form.getCleanedData().get("choice");     
      Choice selected_choice = modelFactory.dao(Choice.class).get(choice);
     
      if (selected_choice == null) {
        Map<String, Object> context = new HashMap<String, Object>();
        context.put("poll", p);
View Full Code Here

TOP

Related Classes of javango.polls.forms.VoteForm

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.