Package javango.forms.fields

Examples of javango.forms.fields.Field


import junit.framework.TestCase;

public class NullFieldTest extends InjectedTestCaseBase {

  public void testNoAllowNull() throws Exception {
    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));
  }
View Full Code Here


    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);
    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

    fullClean();
    if (!errors.isEmpty()) return null;

    for (Entry<String, Object> e : getCleanedData().entrySet()) {
      String fieldName = e.getKey();
      Field f = getFields().get(fieldName);
      if (f == null || f.isEditable()) {
        if (log.isDebugEnabled()) log.debug(String.format("Cleaning : '%s'", fieldName));

        if (log.isDebugEnabled()) log.debug("Found data : '%s'" + e.getValue());
        if (PropertyUtils.isWriteable(bean, fieldName)) {
          try {
View Full Code Here

  public BoundField get(String field) {   
    if (!getFields().containsKey(field)) {
      return null;
    }

    Field f = getFields().get(field);
    if (f.getName() == null) {
      f.setName(field);
    }

    return new BoundField(f, this, f.getName());
  }
View Full Code Here

import junit.framework.TestCase;

public class BooleanFieldTest extends InjectedTestCaseBase {

  public void testRequired() throws Exception {
    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

    assertTrue(errors.containsKey(field.getName()));
    assertEquals("Required", errors.get(field.getName()));
  }
 
  public void testNotRequired() throws Exception {
    Field field = new BooleanField(injector.getInstance(WidgetFactory.class));
    field.setName("fieldName");
    field.setRequired(false);
   
    Map<String, String> errors = new HashMap<String, String>();
   
    field.clean(new String[]{""}, errors);
    assertTrue(errors.isEmpty());
  }
View Full Code Here

    field.clean(new String[]{""}, errors);
    assertTrue(errors.isEmpty());
  }

  public void testInvalid() throws Exception {
    Field field = new BooleanField(injector.getInstance(WidgetFactory.class));
    field.setName("fieldName");
   
    Map<String, String> errors = new HashMap<String, String>();
   
    Boolean value = (Boolean)field.clean(new String []{"qwert"}, errors);
    assertFalse(errors.isEmpty());
    assertTrue(errors.containsKey("fieldName"));
    assertEquals("Unknown value 'qwert'", errors.get("fieldName"));
  }
View Full Code Here

      if (log.isDebugEnabled()) log.debug("Processing Field :" + modelField);
      // first see if this modelform has overridden the field...
      return loadField(findDeclaredField(this.getClass(), modelField.getName()));
    } catch (NoSuchFieldException e) {
      Class type = modelField.getType();
      Field baseField = null;

      baseField = fieldFactory.newFieldForClass(type);
     
      if (baseField != null) {
        baseField.setName(modelField.getName());
        Annotation[] annotations = modelField.getAnnotations();
        for (Annotation annotation: annotations) {
            baseField.handleAnnotation(annotation);
        }
        _fields.put(modelField.getName(), baseField);
      }
      return baseField;
    }
View Full Code Here

    assertTrue(errors.containsKey("fieldName"));
    assertEquals("Unknown value 'qwert'", errors.get("fieldName"));
  }

  public void testValidTrue() throws Exception {
    Field field = new BooleanField(injector.getInstance(WidgetFactory.class));
    field.setName("fieldName");
   
    Map<String, String> errors = new HashMap<String, String>();
   
    Boolean value = (Boolean)field.clean(new String[]{"true"}, errors);
    assertTrue(errors.isEmpty());
    assertEquals(Boolean.TRUE, value);
 
View Full Code Here

    assertTrue(errors.isEmpty());
    assertEquals(Boolean.TRUE, value);
 

  public void testValidFalse() throws Exception {
    Field field = new BooleanField(injector.getInstance(WidgetFactory.class));
    field.setName("fieldName");
   
    Map<String, String> errors = new HashMap<String, String>();
   
    Boolean value = (Boolean)field.clean(new String[]{"false"}, errors);
    assertTrue(errors.isEmpty());
    assertEquals(Boolean.FALSE, 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.