Package javango.forms

Examples of javango.forms.Form


    public CharField myField;

  }
 
  public void testValidatorNotEmpty() throws Exception {
    Form form = injector.getInstance(RequiredTestForm.class).bind(new HashMap<String, String[]>());
    assertFalse(form.isValid());
    Map<String, String>errors = form.getErrors();
    assertTrue(errors.containsKey("myField"));
    assertEquals("may not be null or empty", errors.get("myField"));
  }
View Full Code Here


      throw new Http404("Class not found, or not authorized");
    }
   
    String[] property_list = ma.getListSearchFields();     

    Form form = ma.getSearchForm();

    if (form == null) {
      String[] includeFields = property_list == null ? getIncludeFields(pc) : property_list;

      ModelForm<?> mForm = new ModelForm(fieldFactory, hibernateUtil, managers);
      mForm.setInclude(includeFields);
      mForm.setModel(pc);

      for (Field f : mForm.getFields().values()) {
        f.setRequired(false).setAllowNull(true);
        f.setEditable(true);
        if (f.getClass().equals(CharField.class)) {
          f.setName(f.getName() + "__ilike");
        } else if (f.getClass().equals(DateField.class)) {
          f.setName(f.getName() + "__date");
        } else {
          f.setName(f.getName() + "__eq");
        }
      }
     
      form = mForm;
    }
   

   
    if ("POST".equals(request.getMethod())) {
      form.bind(request.getParameterMap());
      if (form.isValid()) {
        // TODO better way to get the relative 'admin' part of the url
        Map<String, String> params = new HashMap<String, String>();
        generateSearchParams(request, params);
        return new HttpResponseRedirect("../", params);
      }
View Full Code Here

        }
      }

      String[] property_list = ma.getFields();     

      Form form = ma.getForm();
     
      if (form == null) {
        String[] includeFields = property_list == null ? getIncludeFields(pc) : property_list;
 
        ModelForm mForm = new ModelForm(fieldFactory, hibernateUtil, managers);
        if (includeFields != null) mForm.setInclude(includeFields);
        mForm.setModel(pc);
        form = mForm;
      }
     
      if ("POST".equals(request.getMethod())) {
        // update the object
        if (object == null) object=injector.getInstance(pc);
       
        form.bind(request.getParameterMap());
        // form = modelFactory.form(pc.getMappedClass(), request.getParameterMap());
        if (form.isValid()) {
//          if (object_id == null) { // this is a new object
//            if (!bl.canCreate()) {
//              throw new HttpException("Unable to create");
//            }
//          } else {
//            if (!bl.canUpdate(object)) {
//              throw new HttpException("Unable to updte");
//            }
//          }
         
          form.clean(object);
          try {
            if (object_id == null) {
              manager.create(object);
            } else {
              manager.save(object);
            }
           
            if (request.getParameterMap().containsKey("_addanother")) {
              return new HttpResponseRedirect("../add");
            } else if (request.getParameterMap().containsKey("_continue")) {
              return new HttpResponseRedirect(String.format("../%s/", manager.getPk(object)));
            }
            return new HttpResponseRedirect("..");
          } catch (ManagerException e) {
            request.getSession().addError(e.getMessage());
          }
        }
      } else {
        // display the form
        if (object != null) form.setInitial(object);
      }
         
      Map<String, Object> context = new HashMap<String, Object>();
      context.put("property_list", property_list);
      context.put("object", object);
View Full Code Here

    super.setUp();
    injector = Guice.createInjector(new HibernateModule());
  }

  public void testFieldProperties() throws Exception {
    Form form = injector.getInstance(PollForm.class).bind(new HashMap<String, String[]>());
    assertEquals("Question", form.getFields().get("question").getVerboseName());
  }
View Full Code Here

    Form form = injector.getInstance(PollForm.class).bind(new HashMap<String, String[]>());
    assertEquals("Question", form.getFields().get("question").getVerboseName());
  }
 
  public void testFieldOverrideProperties() throws Exception {
    Form form = injector.getInstance(PollForm.class).bind(new HashMap<String, String[]>());
    assertEquals("My cool pubdate", form.getFields().get("pubDate").getVerboseName());
  }
View Full Code Here

  public void testForInstance() throws Exception {
    fixture(2);
    Choice c = (Choice)managers.forClass(Choice.class).get(1L);
    assertNotNull(c);
    Form form = models.forInstance(c);
   
    String expected = "<tr><th><label for='id_choice'>Choice</label></th><td><input maxlength=\"255\" id=\"id_choice\" type=\"text\" name=\"choice\" value=\"Choice A 0\" /></td></tr>\n" +
        "<tr><th><label for='id_poll'>Poll</label></th><td><select id=\"id_poll\" name=\"poll\"><option value=\"\" >--</option>" +
        "<option value=\"1\" selected=\"selected\">AdminTestQuestion : 0</option>" +
        "<option value=\"2\" >AdminTestQuestion : 1</option>" +
        "</select></td></tr>\n" +
        "<tr><th><label for='id_votes'>Votes</label></th><td><input id=\"id_votes\" type=\"text\" name=\"votes\" value=\"0\" /></td></tr>\n";
    assertEquals(expected, form.asTable());
  }
View Full Code Here

    }   
       
  }

  public void testCreateForm() throws Exception {
    Form form = formFactory.forModel(SampleModel.class);
    Map<String, Field<?>> fields = form.getFields();
    assertTrue(fields.containsKey("field"));
    Field<?> field = fields.get("field");
    assertEquals(CharField.class, field.getClass());
    assertEquals("field", field.getName());
  }
View Full Code Here

    assertEquals(CharField.class, field.getClass());
    assertEquals("field", field.getName());
  }
   
  public void testUnboundErrors() throws Exception {
    Form f = formFactory.forModel(ContactBean.class);
    assertFalse(f.isValid());
    Map l = f.getErrors();
    assertNotNull(l);
    assertEquals(l.size(), 0);
  }
View Full Code Here

    m.put("subject", new String[] {"hello"});
    m.put("message", new String[] {"Hi there"});
    m.put("sender", new String[] {"foo@example.com"});
    m.put("cc_myself", new String[] {"true"});
    m.put("value", new String[] {"1234"});
    Form f = formFactory.forModel(ContactBean.class);
    assertFalse(f.isBound());
    f = formFactory.forModel(ContactBean.class).bind(m);
    assertTrue(f.isBound());
  }
View Full Code Here

    m.put("subject", new String[] {"hello"});
    m.put("message", new String[] {"Hi there"});
    m.put("sender", new String[] {"foo@example.com"});
    m.put("ccMyself", new String[] {"true"});
    m.put("value", new String[] {"1234"});
    Form f = formFactory.forModel(ContactBean.class).bind(m).setId(null);
    assertTrue(f.isValid());
    String expected = "<tr><th>Subject</th><td><input type=\"text\" name=\"subject\" value=\"hello\" /></td></tr>\n" +
        "<tr><th>Message</th><td><input type=\"text\" name=\"message\" value=\"Hi there\" /></td></tr>\n" +
        "<tr><th>Sender</th><td><input type=\"text\" name=\"sender\" value=\"foo@example.com\" /></td></tr>\n" +
        "<tr><th>Value</th><td><input type=\"text\" name=\"value\" value=\"1234\" /></td></tr>\n" +
        "<tr><th>Cc Myself</th><td><input type=\"checkbox\" name=\"ccMyself\" checked=\"checked\" /></td></tr>\n";
    assertEquals(expected, f.asTable());

  }
View Full Code Here

TOP

Related Classes of javango.forms.Form

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.