Package javango.forms.fields

Examples of javango.forms.fields.Field.clean()


    choices.put(2L, "Paul");
    Field f = (injector.getInstance(LongSelectField.class)).setChoices(choices).setName("choice_field");
   
    Map<String, String> errors = new HashMap<String, String>();
   
    assertEquals(1L, f.clean(new String[]{"1"}, errors));
    assertTrue(errors.isEmpty());

   
    errors = new HashMap<String, String>();
    f.clean(new String[]{"John"}, errors);
View Full Code Here


    assertEquals(1L, f.clean(new String[]{"1"}, errors));
    assertTrue(errors.isEmpty());

   
    errors = new HashMap<String, String>();
    f.clean(new String[]{"John"}, errors);
    assertEquals("Select a valid choice. That choice is not one of the available choices.", errors.get("choice_field"));   
  }
}
View Full Code Here

    field.setName("fieldName");

    Map<String, String> errors = new HashMap<String, String>();
   
    Calendar expected = new GregorianCalendar(2008, 11, 15); // seriously month is zero based.
    Date value = (Date)field.clean(new String[]{"12/15/2008"}, errors);
    assertEquals(expected.getTime(), value);
  }

  public void test2DigitYear() throws Exception {
    Field field = injector.getInstance(DateField.class);
View Full Code Here

    field.setName("fieldName");

    Map<String, String> errors = new HashMap<String, String>();
   
    Calendar expected = new GregorianCalendar(2008, 11, 15); // seriously month is zero based.
    Date value = (Date)field.clean(new String[]{"12/15/08"}, errors);
    assertEquals(expected.getTime(), value);
  }

  public void test4DigitYearDateTime() throws Exception {
    Field field = injector.getInstance(DateTimeField.class);
View Full Code Here

    field.setName("fieldName");

    Map<String, String> errors = new HashMap<String, String>();
   
    Calendar expected = new GregorianCalendar(2008, 11, 15, 8, 43); // seriously month is zero based.
    Date value = (Date)field.clean(new String[]{"12/15/2008 8:43"}, errors);
    assertEquals(expected.getTime(), value);
  }

  public void test2DigitYearDateTime() throws Exception {
    Field field = injector.getInstance(DateTimeField.class);
View Full Code Here

    field.setName("fieldName");

    Map<String, String> errors = new HashMap<String, String>();
   
    Calendar expected = new GregorianCalendar(2008, 11, 15, 8, 43); // seriously month is zero based.
    Date value = (Date)field.clean(new String[]{"12/15/08 8:43"}, errors);
    assertEquals(expected.getTime(), value);
  }
 
  public void testNoDigitYear() throws Exception {
    Field field = injector.getInstance(DateField.class);
View Full Code Here

    expected.set(Calendar.DAY_OF_MONTH, 15);
    expected.set(Calendar.HOUR_OF_DAY, 0);
    expected.set(Calendar.MINUTE, 0);
    expected.set(Calendar.SECOND, 0);
    expected.set(Calendar.MILLISECOND, 0);
    Date value = (Date)field.clean(new String[]{"12/15"}, errors);
    assertEquals(expected.getTime(), value);
  }
}
View Full Code Here

    Field field = new CharField(injector.getInstance(WidgetFactory.class)).setRequired(false).setAllowNull(false);
    field.setName("fieldName");
   
    Map<String, String> errors = new HashMap<String, String>();
   
    String value = (String)field.clean(new String[]{""}, errors);
    assertTrue(errors.isEmpty());
    assertTrue("".equals(value));
  }
  public void testAllowNull() throws Exception {
    Field field = new CharField(injector.getInstance(WidgetFactory.class)).setRequired(false).setAllowNull(true);
View Full Code Here

    Field field = new CharField(injector.getInstance(WidgetFactory.class)).setRequired(false).setAllowNull(true);
    field.setName("fieldName");
   
    Map<String, String> errors = new HashMap<String, String>();
   
    String value = (String)field.clean(new String[]{""}, errors);
    assertTrue(errors.isEmpty());
    assertTrue(value == null);
  }
}
View Full Code Here

    Field field = new BooleanField(injector.getInstance(WidgetFactory.class));
    field.setName("fieldName");

    Map<String, String> errors = new HashMap<String, String>();
   
    field.clean(new String[]{""}, errors);
    assertFalse(errors.isEmpty());
    assertTrue(errors.containsKey(field.getName()));
    assertEquals("Required", errors.get(field.getName()));
  }
 
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.