Package javango.forms

Examples of javango.forms.Form


    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 = injector.getInstance(ContactForm.class).bind(m);
    assertTrue(f.isValid());
    ContactBean bean = (ContactBean)f.clean(ContactBean.class);
    assertEquals("hello", bean.getSubject());
    assertEquals("Hi there", bean.getMessage());
    assertEquals("foo@example.com", bean.getSender());
    assertEquals(Boolean.TRUE, bean.getCcMyself());
    assertEquals(new Long(1234), bean.getValue());
View Full Code Here


  }
 
  public void testRequireByDefault() throws Exception {
    Map<String, String[]> m = new HashMap<String, String[]>();
    m.put("message", new String[] {"Hi there"});       
    Form f = injector.getInstance(ContactForm.class).bind(m);
    assertFalse(f.isValid());
    Map errors = f.getErrors();
    assertTrue(errors.containsKey("subject"));
    assertTrue(errors.containsKey("sender"));
    assertTrue(errors.containsKey("value"));
  }
View Full Code Here

    m.put("prefix-subject", new String[] {"hello"});
    m.put("prefix-message", new String[] {"Hi there"});
    m.put("prefix-sender", new String[] {"foo@example.com"});
    m.put("prefix-ccMyself", new String[] {"true"});
    m.put("prefix-value", new String[] {"1234"});
    Form f = injector.getInstance(ContactForm.class).bind(m).setPrefix("prefix");
    f.isValid();
    String expected = "<tr><th><label for='id_prefix-subject'>Subject</label></th><td><input id=\"id_prefix-subject\" type=\"text\" name=\"prefix-subject\" value=\"hello\" /></td></tr>\n" +
        "<tr><th><label for='id_prefix-message'>Message</label></th><td><input id=\"id_prefix-message\" type=\"text\" name=\"prefix-message\" value=\"Hi there\" /></td></tr>\n" +
        "<tr><th><label for='id_prefix-sender'>Sender</label></th><td><input id=\"id_prefix-sender\" type=\"text\" name=\"prefix-sender\" value=\"foo@example.com\" /></td></tr>\n" +
        "<tr><th><label for='id_prefix-ccMyself'>Cc Myself</label></th><td><input id=\"id_prefix-ccMyself\" type=\"checkbox\" name=\"prefix-ccMyself\" checked=\"checked\" /></td></tr>\n" +
        "<tr><th><label for='id_prefix-value'>Value</label></th><td><input id=\"id_prefix-value\" type=\"text\" name=\"prefix-value\" value=\"1234\" /></td></tr>\n";
    assertEquals(expected, f.asTable());
  }
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 = injector.getInstance(ContactForm.class).bind(m);
    f.isValid();
    String expected = "<tr><th><label for='id_subject'>Subject</label></th><td><input id=\"id_subject\" type=\"text\" name=\"subject\" value=\"hello\" /></td></tr>\n" +
        "<tr><th><label for='id_message'>Message</label></th><td><input id=\"id_message\" type=\"text\" name=\"message\" value=\"Hi there\" /></td></tr>\n" +
        "<tr><th><label for='id_sender'>Sender</label></th><td><input id=\"id_sender\" type=\"text\" name=\"sender\" value=\"foo@example.com\" /></td></tr>\n" +
        "<tr><th><label for='id_ccMyself'>Cc Myself</label></th><td><input id=\"id_ccMyself\" type=\"checkbox\" name=\"ccMyself\" checked=\"checked\" /></td></tr>\n" +
        "<tr><th><label for='id_value'>Value</label></th><td><input id=\"id_value\" type=\"text\" name=\"value\" value=\"1234\" /></td></tr>\n";
    assertEquals(expected, f.asTable());
  }
View Full Code Here

      getFields().put("value", factory.newField(LongField.class));
    }     
  }
 
  public void testNullName() throws Exception {
    Form f = injector.getInstance(ContactForm.class).setId(null);
    String expected = "<input type=\"text\" name=\"value\" />";   
    assertEquals(expected, f.get("value").toString());

    expected = "<tr><th>Value</th><td><input type=\"text\" name=\"value\" /></td></tr>\n";
    String html = f.asTable();
    assertEquals(expected, html);
  }
View Full Code Here

 
  public void testChanged() throws Exception {
    Map<String, String[]> m = new HashMap<String, String[]>();

    m.put("prefix-newvalue", new String[] {"1234"});
    Form f = injector.getInstance(ContactForm.class);
    f.getFields().get("value").setName("newvalue");
    f.bind(m).setPrefix("prefix").setId(null);
    f.isValid();
    String expected = "<input type=\"text\" name=\"prefix-newvalue\" value=\"1234\" />";   
    assertEquals(expected, f.get("value").toString());
   
    expected = "<tr><th>Newvalue</th><td><input type=\"text\" name=\"prefix-newvalue\" value=\"1234\" /></td></tr>\n";
    String html = f.asTable();
    assertEquals(expected, html);
  }
View Full Code Here

    String html = f.asTable();
    assertEquals(expected, html);
  }
 
  public void testFieldIteration() throws Exception {
    Form f = injector.getInstance(ContactForm.class).setPrefix("prefix").setId(null);
    f.getFields().get("value").setName("newvalue");
    List<String> expected = new ArrayList<String>();
    expected.add("<input type=\"text\" name=\"prefix-newvalue\" />");
   
    Iterator<String> i = expected.iterator();
    for (BoundField field : f) {
View Full Code Here

      super(factory);
    }   
  }

  public void testUnboundHtml() throws Exception {
    Form f = injector.getInstance(ContactForm.class);
    String expected = "<tr><th><label for='id_subject'>Subject</label></th><td><input id=\"id_subject\" type=\"text\" name=\"subject\" /></td></tr>\n" +
        "<tr><th><label for='id_message'>Message</label></th><td><input id=\"id_message\" type=\"text\" name=\"message\" /></td></tr>\n" +
        "<tr><th><label for='id_sender'>Sender</label></th><td><input id=\"id_sender\" type=\"text\" name=\"sender\" /></td></tr>\n" +
        "<tr><th><label for='id_cost'>Cost</label></th><td><input id=\"id_cost\" type=\"text\" name=\"cost\" /></td></tr>\n" +
        "<tr><th><label for='id_ccMyself'>Carbon Copy Myself</label></th><td><input id=\"id_ccMyself\" type=\"checkbox\" name=\"ccMyself\" /></td></tr>\n" +
        "<tr><th><label for='id_value'>The Value</label></th><td><input id=\"id_value\" type=\"text\" name=\"value\" />" +
        "<input id=\"id_hiddenField\" type=\"hidden\" name=\"hiddenField\" />\n</td></tr>\n";
    assertEquals(expected, f.asTable());
  }
View Full Code Here

    m.put("message", new String[] {"Hi there"});
    m.put("sender", new String[] {"foo@example.com"});
    m.put("cost", new String[] {"1.23"});
    m.put("ccMyself", new String[] {"true"});
    m.put("value", new String[] {"1234"});
    Form f = injector.getInstance(ContactForm.class).bind(m).setId(null);
    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>Cost</th><td><input type=\"text\" name=\"cost\" value=\"1.23\" /></td></tr>\n" +
        "<tr><th>Carbon Copy Myself</th><td><input type=\"checkbox\" name=\"ccMyself\" checked=\"checked\" /></td></tr>\n" +
        "<tr><th>The Value</th><td><input type=\"text\" name=\"value\" value=\"1234\" />" +
        "<input type=\"hidden\" name=\"hiddenField\" />\n</td></tr>\n";
    assertEquals(expected, f.asTable());
  }
View Full Code Here

    m.put("message", new String[] {"Hi there"});
    m.put("sender", new String[] {"foo@example.com"});
    m.put("cost", new String[] {"1.23"});
    m.put("ccMyself", new String[] {"true"});
    m.put("value", new String[] {"1234"});
    Form f = injector.getInstance(ContactForm.class).bind(m).setId(null);
    f.isValid();
    String expected = "<tr><th>Subject</th><td><ul class=\"errorlist\"><li>This field is required.</li></ul><input type=\"text\" name=\"subject\" /></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>Cost</th><td><input type=\"text\" name=\"cost\" value=\"1.23\" /></td></tr>\n" +
        "<tr><th>Carbon Copy Myself</th><td><input type=\"checkbox\" name=\"ccMyself\" checked=\"checked\" /></td></tr>\n" +
        "<tr><th>The Value</th><td><input type=\"text\" name=\"value\" value=\"1234\" />" +
        "<input type=\"hidden\" name=\"hiddenField\" value=\"hidden value\" />\n</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.