Package org.springframework.validation

Examples of org.springframework.validation.BeanPropertyBindingResult


  /**
   * http://opensource.atlassian.com/projects/spring/browse/SPR-4005
   */
  public void testOmittedPathMatchesObjectErrorsOnly() throws Exception {
    this.tag.setPath(null);
    Errors errors = new BeanPropertyBindingResult(new TestBean(), "COMMAND_NAME");
    errors.reject("some.code", "object error");
    errors.rejectValue("name", "some.code", "field error");
    exposeBindingResult(errors);
    this.tag.doStartTag();
    assertNotNull(getPageContext().getAttribute(ErrorsTag.MESSAGES_ATTRIBUTE));
    this.tag.doEndTag();
    String output = getOutput();
View Full Code Here


  private void assertWhenNoErrorsExistingMessagesInScopeAreNotClobbered(int scope) throws JspException {
    String existingAttribute = "something";
    getPageContext().setAttribute(ErrorsTag.MESSAGES_ATTRIBUTE, existingAttribute, scope);

    Errors errors = new BeanPropertyBindingResult(new TestBean(), "COMMAND_NAME");
    exposeBindingResult(errors);
    int result = this.tag.doStartTag();
    assertEquals(Tag.SKIP_BODY, result);

    result = this.tag.doEndTag();
View Full Code Here

  public void testWithCheckedObjectValueAndEditor() throws Exception {
    this.tag.setPath("myFloat");
    this.tag.setValue("F12.99");

    BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(this.bean, COMMAND_NAME);
    MyFloatEditor editor = new MyFloatEditor();
    bindingResult.getPropertyEditorRegistry().registerCustomEditor(Float.class, editor);
    getPageContext().getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + COMMAND_NAME, bindingResult);

    int result = this.tag.doStartTag();
    assertEquals(Tag.SKIP_BODY, result);
View Full Code Here

  public void testCollectionOfPetsWithEditor() throws Exception {
    this.tag.setPath("pets");
    this.tag.setValue(new ItemPet("Rudiger"));

    BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(this.bean, COMMAND_NAME);
    PropertyEditorSupport editor = new ItemPet.CustomEditor();
    bindingResult.getPropertyEditorRegistry().registerCustomEditor(ItemPet.class, editor);
    getPageContext().getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + COMMAND_NAME, bindingResult);

    int result = this.tag.doStartTag();
    assertEquals(Tag.SKIP_BODY, result);
View Full Code Here

  }

  public void testWithListAndTransformTagAndEditor() throws Exception {
    this.tag.setPath("realCountry");
    this.tag.setItems("${countries}");
    BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(getTestBean(), "testBean");
    bindingResult.getPropertyAccessor().registerCustomEditor(Country.class, new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue(new Country(text, ""));
      }
      public String getAsText() {
        return ((Country) getValue()).getName();
View Full Code Here

    assertEquals("'34' node not selected", "selected", e.attribute("selected").getValue());
  }

  public void testWithFloatCustom() throws Exception {
    PropertyEditor propertyEditor = new SimpleFloatEditor();
    BeanPropertyBindingResult errors = new BeanPropertyBindingResult(getTestBean(), COMMAND_NAME);
    errors.getPropertyAccessor().registerCustomEditor(Float.class, propertyEditor);
    exposeBindingResult(errors);

    this.tag.setPath("myFloat");

    Float[] array = new Float[] {
View Full Code Here

    List list = new ArrayList();
    list.add(Country.COUNTRY_UK);
    list.add(Country.COUNTRY_AT);
    this.bean.setSomeList(list);

    BeanPropertyBindingResult errors = new BeanPropertyBindingResult(this.bean, COMMAND_NAME);
    errors.getPropertyAccessor().registerCustomEditor(List.class, new CustomCollectionEditor(LinkedList.class) {
      public String getAsText() {
        return getValue().toString();
      }
    });
    exposeBindingResult(errors);
View Full Code Here

      this.tag.setPath("someMap"); // see: TestBean
      this.tag.setItems("${countryToLocaleMap}"); // see: extendRequest()
      this.tag.setItemValue("isoCode"); // Map key: Country
      this.tag.setItemLabel("displayLanguage"); // Map value: Locale

      BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(getTestBean(), COMMAND_NAME);
      bindingResult.getPropertyAccessor().registerCustomEditor(Country.class, new PropertyEditorSupport() {

        public void setAsText(final String text) throws IllegalArgumentException {
          setValue(Country.getCountryWithIsoCode(text));
        }
View Full Code Here

  }

  public void testWithCustomBinder() throws Exception {
    this.tag.setPath("myFloat");

    BeanPropertyBindingResult errors = new BeanPropertyBindingResult(this.bean, COMMAND_NAME);
    errors.getPropertyAccessor().registerCustomEditor(Float.class, new SimpleFloatEditor());
    exposeBindingResult(errors);

    assertEquals(Tag.SKIP_BODY, this.tag.doStartTag());

    String output = getOutput();
View Full Code Here

  public void testWithSingleValueAndEditor() throws Exception {
    this.bean.setName("Rob Harrop");
    this.tag.setPath("name");
    this.tag.setValue("   Rob Harrop");
    BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(this.bean, COMMAND_NAME);
    bindingResult.getPropertyEditorRegistry().registerCustomEditor(String.class, new StringTrimmerEditor(false));
    getPageContext().getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + COMMAND_NAME, bindingResult);

    int result = this.tag.doStartTag();
    assertEquals(Tag.SKIP_BODY, result);
View Full Code Here

TOP

Related Classes of org.springframework.validation.BeanPropertyBindingResult

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.