Package java.beans

Examples of java.beans.PropertyEditorSupport


  }

  public void testStringPropertyWithCustomEditor() throws Exception {
    TestBean tb = new TestBean();
    BeanWrapper bw = new BeanWrapperImpl(tb);
    bw.registerCustomEditor(String.class, "name", new PropertyEditorSupport() {
      public void setValue(Object value) {
        if (value instanceof String[]) {
          setValue(StringUtils.arrayToDelimitedString(((String[]) value), "-"));
        }
        else {
View Full Code Here


  }

  public void testIntArrayPropertyWithCustomEditor() {
    PropsTest pt = new PropsTest();
    BeanWrapper bw = new BeanWrapperImpl(pt);
    bw.registerCustomEditor(int.class, new PropertyEditorSupport() {
      public void setAsText(String text) {
        setValue(new Integer(Integer.parseInt(text) + 1));
      }
    });
View Full Code Here

  }

  public void testMapAccessWithTypeConversion() {
    IndexedTestBean bean = new IndexedTestBean();
    BeanWrapper bw = new BeanWrapperImpl(bean);
    bw.registerCustomEditor(TestBean.class, new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        if (!StringUtils.hasLength(text)) {
          throw new IllegalArgumentException();
        }
        setValue(new TestBean(text));
View Full Code Here

  }

  public void testMapAccessWithUnmodifiableMap() {
    IndexedTestBean bean = new IndexedTestBean();
    BeanWrapper bw = new BeanWrapperImpl(bean);
    bw.registerCustomEditor(TestBean.class, "map", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        if (!StringUtils.hasLength(text)) {
          throw new IllegalArgumentException();
        }
        setValue(new TestBean(text));
View Full Code Here

  }

  public void testMapAccessWithCustomUnmodifiableMap() {
    IndexedTestBean bean = new IndexedTestBean();
    BeanWrapper bw = new BeanWrapperImpl(bean);
    bw.registerCustomEditor(TestBean.class, "map", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        if (!StringUtils.hasLength(text)) {
          throw new IllegalArgumentException();
        }
        setValue(new TestBean(text));
View Full Code Here

  }

  public void testLargeMatchingPrimitiveArrayWithSpecificEditor() {
    PrimitiveArrayBean tb = new PrimitiveArrayBean();
    BeanWrapper bw = new BeanWrapperImpl(tb);
    bw.registerCustomEditor(int.class, "array", new PropertyEditorSupport() {
      public void setValue(Object value) {
        if (value instanceof Integer) {
          super.setValue(new Integer(((Integer) value).intValue() + 1));
        }
      }
View Full Code Here

  }

  public void testLargeMatchingPrimitiveArrayWithIndexSpecificEditor() {
    PrimitiveArrayBean tb = new PrimitiveArrayBean();
    BeanWrapper bw = new BeanWrapperImpl(tb);
    bw.registerCustomEditor(int.class, "array[1]", new PropertyEditorSupport() {
      public void setValue(Object value) {
        if (value instanceof Integer) {
          super.setValue(new Integer(((Integer) value).intValue() + 1));
        }
      }
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

        return masterInstance;
    }
    private WOJServer newWojServer(String mode) {
        try {
            XmlBeanFactory f = new XmlBeanFactory(new ClassPathResource(getSpringConfigFile(_properties, mode), WOJServerFactory.class));
            f.registerCustomEditor(long.class, new PropertyEditorSupport() {
                public void setAsText(String text) throws IllegalArgumentException {
                    if (text.startsWith("0x")) {
                        setValue(new Long(Long.parseLong(text.substring(2), 16)));
                    } else {
                        setValue(new Long(Long.parseLong(text, 10)));
View Full Code Here

   * @param request
   */
//  @InitBinder
  protected void initBinder(WebDataBinder binder, final HttpServletRequest request) {
   
    binder.registerCustomEditor(Date.class, new PropertyEditorSupport(){
      @Override
      public String getAsText() {
        return createDateFormat().format(getValue());
      }
      @Override
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.