Package javango.forms.fields

Examples of javango.forms.fields.Field


    if (form.getErrors() == null && !form.isValid()) return false;
   
    ClassValidator validator = new ClassValidator(form.getClass());
    Iterator<Field<?>> i = form.getFields().values().iterator();
    while (i.hasNext()) {
      Field f  = i.next();
      InvalidValue[] invalids = validator.getPotentialInvalidValues(f.getName(), form.getCleanedData().get(f.getName()));
      for (int x=0; x<invalids.length; x++) {
        form.getErrors().put(invalids[x].getPropertyName(), invalids[x].getMessage());
      }
    }
   
View Full Code Here


  public void testModelFormAddField() throws Exception {
    Form form = injector.getInstance(EnhancedContactForm.class);
//    Form form = new EnhancedContactForm();
    assertTrue(form.getFields().containsKey("newField"));
    assertTrue(form.getFields().containsKey("ccMyself"));
    Field ccField = form.getFields().get("ccMyself");
    assertEquals(LongField.class, ccField.getClass());
  }
View Full Code Here

    Form form = injector.getInstance(NewContactForm.class);
//    Form form = new EnhancedContactForm();
    assertTrue(form.getFields().containsKey("newField"));
    assertTrue(form.getFields().containsKey("ccMyself"));
    assertTrue(!form.getFields().containsKey("subject"));
    Field ccField = form.getFields().get("ccMyself");
    assertEquals(LongField.class, ccField.getClass());
  }
View Full Code Here

    }
   
  }
 
  public void testDefaultWidget() throws Exception {
    Field f = new SelectField(injector.getInstance(WidgetFactory.class));
    assertEquals(SelectWidget.class, f.getWidget().getClass());
  }
View Full Code Here

 
  public void testLongGetByValue() throws Exception {
    Map<Long, String> choices = new HashMap<Long, String>();
    choices.put(1L, "John");
    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);
    assertEquals("Select a valid choice. That choice is not one of the available choices.", errors.get("choice_field"));   
  }
View Full Code Here

import junit.framework.TestCase;

public class DateFieldTest extends InjectedTestCaseBase {

  public void test4DigitYear() throws Exception {
    Field field = injector.getInstance(DateField.class);
    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);
  }
View Full Code Here

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

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

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

    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);
    field.setName("fieldName");

    Map<String, String> errors = new HashMap<String, String>();
       
    Calendar expected = new GregorianCalendar();
    expected.set(Calendar.MONTH, 11);
    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

TOP

Related Classes of javango.forms.fields.Field

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.