Package java.beans

Examples of java.beans.PropertyEditorSupport


  }

  public void testBindToStringArrayWithComponentEditor() {
    TestBean tb = new TestBean();
    DataBinder binder = new DataBinder(tb, "tb");
    binder.registerCustomEditor(String.class, "stringArray", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue("X" + text);
      }
    });
    MutablePropertyValues pvs = new MutablePropertyValues();
View Full Code Here


  public void testNestedBindWithPropertyEditor() {
    TestBean bean = new TestBean();

    PortletRequestDataBinder binder = new PortletRequestDataBinder(bean);
    binder.registerCustomEditor(ITestBean.class, new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue(new TestBean(text));
      }
    });
View Full Code Here

    this.tag.setItems(allPets);
    this.tag.setItemLabel("label");
    this.tag.setId("myId");

    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 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 testBindingWithErrorsAndCustomEditors() throws Exception {
    FieldAccessBean rod = new FieldAccessBean();
    DataBinder binder = new DataBinder(rod, "person");
    binder.initDirectFieldAccess();
    binder.registerCustomEditor(TestBean.class, "spouse", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue(new TestBean(text, 0));
      }
      public String getAsText() {
        return ((TestBean) getValue()).getName();
View Full Code Here

    this.tag.setItems(allPets);
    this.tag.setItemLabel("label");
    this.tag.setId("myId");

    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

      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 testConvertClassToString() {
    MutablePropertyValues values = new MutablePropertyValues();
    values.addPropertyValue("name", Integer.class);
    TestBean tb = new TestBean();
    BeanWrapper bw = new BeanWrapperImpl(tb);
    bw.registerCustomEditor(String.class, new PropertyEditorSupport() {
      public void setValue(Object value) {
        super.setValue(value.toString());
      }
    });
    bw.setPropertyValues(values);
View Full Code Here

  }

  public void testStringArrayPropertyWithCustomStringEditor() throws Exception {
    PropsTest pt = new PropsTest();
    BeanWrapper bw = new BeanWrapperImpl(pt);
    bw.registerCustomEditor(String.class, "stringArray", new PropertyEditorSupport() {
      public void setAsText(String text) {
        setValue(text.substring(1));
      }
    });
View Full Code Here

TOP

Related Classes of java.beans.PropertyEditorSupport

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.