Package javango.forms.fields

Examples of javango.forms.fields.IntegerField


  }

  private Form createControlForm() throws ValidationException {
    Form controlForm = forms.newForm(AbstractForm.class);
    controlForm.setPrefix(String.format("%s_CTRL", prefix));
    final IntegerField countField = fieldFactory.newField(IntegerField.class);
    countField.setName(formCountFieldName)
      .setWidget(HiddenInputWidget.class)
      .setRequired(true)     
      .setAllowNull(false);
    controlForm.getFields().put(formCountFieldName, countField);
   
    final IntegerField initialFormCount = fieldFactory.newField(IntegerField.class);
    initialFormCount.setName(initialFormCountFieldName)
      .setWidget(HiddenInputWidget.class)
      .setRequired(true)     
      .setAllowNull(false);
    controlForm.getFields().put(initialFormCountFieldName, initialFormCount);
   
View Full Code Here


import javango.forms.widgets.WidgetFactory;

public class IntegerFieldTest extends InjectedTestCaseBase {

  public void testRequired() throws Exception {
    Field field = new IntegerField(injector.getInstance(WidgetFactory.class));
    field.setName("fieldName");

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

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

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

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

    assertTrue(errors.containsKey("fieldName"));
    assertEquals("Integer number not valid", errors.get("fieldName"));
  }

  public void testValid() throws Exception {
    IntegerField field = new IntegerField(injector.getInstance(WidgetFactory.class));
    field.setName("fieldName");
   
    Map<String, String> errors = new HashMap<String, String>();
   
    Integer value = field.clean(new String[]{"1234"}, errors);
    assertTrue(errors.isEmpty());
    assertEquals(new Integer(1234), value);
 
View Full Code Here

TOP

Related Classes of javango.forms.fields.IntegerField

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.