当前位置: 首页>>代码示例>>Java>>正文


Java PropertyEditorSupport类代码示例

本文整理汇总了Java中java.beans.PropertyEditorSupport的典型用法代码示例。如果您正苦于以下问题:Java PropertyEditorSupport类的具体用法?Java PropertyEditorSupport怎么用?Java PropertyEditorSupport使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PropertyEditorSupport类属于java.beans包,在下文中一共展示了PropertyEditorSupport类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testRemovePropertyChangeListener_diff

import java.beans.PropertyEditorSupport; //导入依赖的package包/类
public void testRemovePropertyChangeListener_diff() {
    MockTarget target = new MockTarget();
    PropertyEditorSupport support = new PropertyEditorSupport();
    PropertyChangeListener proxy = EventHandler.create(
            PropertyChangeListener.class, target, "eventSource", "source");
    support.addPropertyChangeListener(proxy);
    support.firePropertyChange();
    assertSame(support, target.getEventSource());

    target.setEventSource(null);
    PropertyChangeListener proxy2 = EventHandler.create(
            PropertyChangeListener.class, target, "eventSource", "source");
    support.removePropertyChangeListener(proxy2);
    support.firePropertyChange();
    assertSame(support, target.getEventSource());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:17,代码来源:PropertyEditorSupportTest.java

示例2: getPropertyEditor

import java.beans.PropertyEditorSupport; //导入依赖的package包/类
@Override
public PropertyEditor getPropertyEditor() {
    return new PropertyEditorSupport() {
        @Override
        public void setAsText(String text) throws IllegalArgumentException {
            if (text instanceof String) {
                try {
                    entry.setMessage(!text.equals("") ? text : null);
                } catch (IOException ex) {
                    History.LOG.log(Level.WARNING, null, ex);
                }
                return;
            }
            throw new java.lang.IllegalArgumentException(text);
        }
        @Override
        public String getAsText() {
            return te.getDisplayValue();
        }
    };
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:RevisionNode.java

示例3: nestedBindWithPropertyEditor

import java.beans.PropertyEditorSupport; //导入依赖的package包/类
@Test
public void nestedBindWithPropertyEditor() {
	PortletRequestDataBinder binder = new PortletRequestDataBinder(bean);
	binder.registerCustomEditor(ITestBean.class, new PropertyEditorSupport() {
		@Override
		public void setAsText(String text) throws IllegalArgumentException {
			setValue(new TestBean(text));
		}
	});

	request.addParameter("spouse", "test");
	request.addParameter("spouse.age", "32");
	binder.bind(request);

	assertNotNull(bean.getSpouse());
	assertEquals("test", bean.getSpouse().getName());
	assertEquals(32, bean.getSpouse().getAge());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:PortletRequestDataBinderTests.java

示例4: testBindingWithNestedObjectCreation

import java.beans.PropertyEditorSupport; //导入依赖的package包/类
@Test
public void testBindingWithNestedObjectCreation() throws Exception {
	TestBean tb = new TestBean();

	DataBinder binder = new DataBinder(tb, "person");
	binder.registerCustomEditor(ITestBean.class, new PropertyEditorSupport() {
		@Override
		public void setAsText(String text) throws IllegalArgumentException {
			setValue(new TestBean());
		}
	});

	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("spouse", "someValue");
	pvs.add("spouse.name", "test");
	binder.bind(pvs);

	assertNotNull(tb.getSpouse());
	assertEquals("test", tb.getSpouse().getName());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:DataBinderTests.java

示例5: testCustomEditorForPrimitiveProperty

import java.beans.PropertyEditorSupport; //导入依赖的package包/类
@Test
public void testCustomEditorForPrimitiveProperty() {
	TestBean tb = new TestBean();
	DataBinder binder = new DataBinder(tb, "tb");

	binder.registerCustomEditor(int.class, "age", new PropertyEditorSupport() {
		@Override
		public void setAsText(String text) throws IllegalArgumentException {
			setValue(new Integer(99));
		}

		@Override
		public String getAsText() {
			return "argh";
		}
	});

	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("age", "");
	binder.bind(pvs);

	assertEquals("argh", binder.getBindingResult().getFieldValue("age"));
	assertEquals(99, tb.getAge());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:DataBinderTests.java

示例6: testEditorForNestedIndexedField

import java.beans.PropertyEditorSupport; //导入依赖的package包/类
@Test
public void testEditorForNestedIndexedField() {
	IndexedTestBean tb = new IndexedTestBean();
	tb.getArray()[0].setNestedIndexedBean(new IndexedTestBean());
	tb.getArray()[1].setNestedIndexedBean(new IndexedTestBean());
	DataBinder binder = new DataBinder(tb, "tb");
	binder.registerCustomEditor(String.class, "array.nestedIndexedBean.list.name", new PropertyEditorSupport() {
		@Override
		public void setAsText(String text) throws IllegalArgumentException {
			setValue("list" + text);
		}
		@Override
		public String getAsText() {
			return ((String) getValue()).substring(4);
		}
	});
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("array[0].nestedIndexedBean.list[0].name", "test1");
	pvs.add("array[1].nestedIndexedBean.list[1].name", "test2");
	binder.bind(pvs);
	assertEquals("listtest1", ((TestBean)tb.getArray()[0].getNestedIndexedBean().getList().get(0)).getName());
	assertEquals("listtest2", ((TestBean)tb.getArray()[1].getNestedIndexedBean().getList().get(1)).getName());
	assertEquals("test1", binder.getBindingResult().getFieldValue("array[0].nestedIndexedBean.list[0].name"));
	assertEquals("test2", binder.getBindingResult().getFieldValue("array[1].nestedIndexedBean.list[1].name"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:26,代码来源:DataBinderTests.java

示例7: testSpecificEditorForNestedIndexedField

import java.beans.PropertyEditorSupport; //导入依赖的package包/类
@Test
public void testSpecificEditorForNestedIndexedField() {
	IndexedTestBean tb = new IndexedTestBean();
	tb.getArray()[0].setNestedIndexedBean(new IndexedTestBean());
	tb.getArray()[1].setNestedIndexedBean(new IndexedTestBean());
	DataBinder binder = new DataBinder(tb, "tb");
	binder.registerCustomEditor(String.class, "array[0].nestedIndexedBean.list.name", new PropertyEditorSupport() {
		@Override
		public void setAsText(String text) throws IllegalArgumentException {
			setValue("list" + text);
		}
		@Override
		public String getAsText() {
			return ((String) getValue()).substring(4);
		}
	});
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("array[0].nestedIndexedBean.list[0].name", "test1");
	pvs.add("array[1].nestedIndexedBean.list[1].name", "test2");
	binder.bind(pvs);
	assertEquals("listtest1", ((TestBean)tb.getArray()[0].getNestedIndexedBean().getList().get(0)).getName());
	assertEquals("test2", ((TestBean)tb.getArray()[1].getNestedIndexedBean().getList().get(1)).getName());
	assertEquals("test1", binder.getBindingResult().getFieldValue("array[0].nestedIndexedBean.list[0].name"));
	assertEquals("test2", binder.getBindingResult().getFieldValue("array[1].nestedIndexedBean.list[1].name"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:26,代码来源:DataBinderTests.java

示例8: testInnerSpecificEditorForNestedIndexedField

import java.beans.PropertyEditorSupport; //导入依赖的package包/类
@Test
public void testInnerSpecificEditorForNestedIndexedField() {
	IndexedTestBean tb = new IndexedTestBean();
	tb.getArray()[0].setNestedIndexedBean(new IndexedTestBean());
	tb.getArray()[1].setNestedIndexedBean(new IndexedTestBean());
	DataBinder binder = new DataBinder(tb, "tb");
	binder.registerCustomEditor(String.class, "array.nestedIndexedBean.list[0].name", new PropertyEditorSupport() {
		@Override
		public void setAsText(String text) throws IllegalArgumentException {
			setValue("list" + text);
		}
		@Override
		public String getAsText() {
			return ((String) getValue()).substring(4);
		}
	});
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("array[0].nestedIndexedBean.list[0].name", "test1");
	pvs.add("array[1].nestedIndexedBean.list[1].name", "test2");
	binder.bind(pvs);
	assertEquals("listtest1", ((TestBean)tb.getArray()[0].getNestedIndexedBean().getList().get(0)).getName());
	assertEquals("test2", ((TestBean)tb.getArray()[1].getNestedIndexedBean().getList().get(1)).getName());
	assertEquals("test1", binder.getBindingResult().getFieldValue("array[0].nestedIndexedBean.list[0].name"));
	assertEquals("test2", binder.getBindingResult().getFieldValue("array[1].nestedIndexedBean.list[1].name"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:26,代码来源:DataBinderTests.java

示例9: testBindToStringArrayWithArrayEditor

import java.beans.PropertyEditorSupport; //导入依赖的package包/类
@Test
public void testBindToStringArrayWithArrayEditor() {
	TestBean tb = new TestBean();
	DataBinder binder = new DataBinder(tb, "tb");
	binder.registerCustomEditor(String[].class, "stringArray", new PropertyEditorSupport() {
		@Override
		public void setAsText(String text) throws IllegalArgumentException {
			setValue(StringUtils.delimitedListToStringArray(text, "-"));
		}
	});
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("stringArray", "a1-b2");
	binder.bind(pvs);
	assertTrue(!binder.getBindingResult().hasErrors());
	assertEquals(2, tb.getStringArray().length);
	assertEquals("a1", tb.getStringArray()[0]);
	assertEquals("b2", tb.getStringArray()[1]);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:DataBinderTests.java

示例10: testBindToStringArrayWithComponentEditor

import java.beans.PropertyEditorSupport; //导入依赖的package包/类
@Test
public void testBindToStringArrayWithComponentEditor() {
	TestBean tb = new TestBean();
	DataBinder binder = new DataBinder(tb, "tb");
	binder.registerCustomEditor(String.class, "stringArray", new PropertyEditorSupport() {
		@Override
		public void setAsText(String text) throws IllegalArgumentException {
			setValue("X" + text);
		}
	});
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("stringArray", new String[] {"a1", "b2"});
	binder.bind(pvs);
	assertTrue(!binder.getBindingResult().hasErrors());
	assertEquals(2, tb.getStringArray().length);
	assertEquals("Xa1", tb.getStringArray()[0]);
	assertEquals("Xb2", tb.getStringArray()[1]);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:DataBinderTests.java

示例11: withListAndTransformTagAndEditor

import java.beans.PropertyEditorSupport; //导入依赖的package包/类
@Test
public void withListAndTransformTagAndEditor() throws Exception {
	this.tag.setPath("realCountry");
	this.tag.setItems(Country.getCountries());
	BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(getTestBean(), "testBean");
	bindingResult.getPropertyAccessor().registerCustomEditor(Country.class, new PropertyEditorSupport() {
		@Override
		public void setAsText(String text) throws IllegalArgumentException {
			setValue(Country.getCountryWithIsoCode(text));
		}
		@Override
		public String getAsText() {
			return ((Country) getValue()).getName();
		}
	});
	getPageContext().getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "testBean", bindingResult);
	this.tag.doStartTag();

	TransformTag transformTag = new TransformTag();
	transformTag.setValue(Country.getCountries().get(0));
	transformTag.setVar("key");
	transformTag.setParent(this.tag);
	transformTag.setPageContext(getPageContext());
	transformTag.doStartTag();
	assertEquals("Austria", getPageContext().findAttribute("key"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:27,代码来源:SelectTagTests.java

示例12: withListAndEditor

import java.beans.PropertyEditorSupport; //导入依赖的package包/类
@Test
public void withListAndEditor() throws Exception {
	this.tag.setPath("realCountry");
	this.tag.setItems(Country.getCountries());
	this.tag.setItemValue("isoCode");
	this.tag.setItemLabel("name");
	BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(getTestBean(), "testBean");
	bindingResult.getPropertyAccessor().registerCustomEditor(Country.class, new PropertyEditorSupport() {
		@Override
		public void setAsText(String text) throws IllegalArgumentException {
			setValue(Country.getCountryWithIsoCode(text));
		}
		@Override
		public String getAsText() {
			return ((Country) getValue()).getName();
		}
	});
	getPageContext().getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "testBean", bindingResult);
	this.tag.doStartTag();
	String output = getOutput();
	assertTrue(output.startsWith("<select "));
	assertTrue(output.endsWith("</select>"));
	assertTrue(output.contains("option value=\"AT\" selected=\"selected\">Austria"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:SelectTagTests.java

示例13: nestedPathWithListAndEditor

import java.beans.PropertyEditorSupport; //导入依赖的package包/类
@Test
public void nestedPathWithListAndEditor() throws Exception {
	this.tag.setPath("bean.realCountry");
	this.tag.setItems(Country.getCountries());
	this.tag.setItemValue("isoCode");
	this.tag.setItemLabel("name");
	TestBeanWrapper testBean = new TestBeanWrapper();
	testBean.setBean(getTestBean());
	BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(testBean , "testBean");
	bindingResult.getPropertyAccessor().registerCustomEditor(Country.class, new PropertyEditorSupport() {
		@Override
		public void setAsText(String text) throws IllegalArgumentException {
			setValue(Country.getCountryWithIsoCode(text));
		}
		@Override
		public String getAsText() {
			return ((Country) getValue()).getName();
		}
	});
	getPageContext().getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "testBean", bindingResult);
	this.tag.doStartTag();
	String output = getOutput();
	assertTrue(output.startsWith("<select "));
	assertTrue(output.endsWith("</select>"));
	assertTrue(output.contains("option value=\"AT\" selected=\"selected\">Austria"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:27,代码来源:SelectTagTests.java

示例14: testBindingWithNestedObjectCreation

import java.beans.PropertyEditorSupport; //导入依赖的package包/类
@Test
public void testBindingWithNestedObjectCreation() throws Exception {
	TestBean tb = new TestBean();

	WebRequestDataBinder binder = new WebRequestDataBinder(tb, "person");
	binder.registerCustomEditor(ITestBean.class, new PropertyEditorSupport() {
		@Override
		public void setAsText(String text) throws IllegalArgumentException {
			setValue(new TestBean());
		}
	});

	MockHttpServletRequest request = new MockHttpServletRequest();
	request.addParameter("spouse", "someValue");
	request.addParameter("spouse.name", "test");
	binder.bind(new ServletWebRequest(request));

	assertNotNull(tb.getSpouse());
	assertEquals("test", tb.getSpouse().getName());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:WebRequestDataBinderTests.java

示例15: testBindingWithNestedObjectCreation

import java.beans.PropertyEditorSupport; //导入依赖的package包/类
@Test
public void testBindingWithNestedObjectCreation() throws Exception {
	TestBean tb = new TestBean();

	ServletRequestDataBinder binder = new ServletRequestDataBinder(tb, "person");
	binder.registerCustomEditor(ITestBean.class, new PropertyEditorSupport() {
		@Override
		public void setAsText(String text) throws IllegalArgumentException {
			setValue(new TestBean());
		}
	});

	MockHttpServletRequest request = new MockHttpServletRequest();
	request.addParameter("spouse", "someValue");
	request.addParameter("spouse.name", "test");
	binder.bind(request);

	assertNotNull(tb.getSpouse());
	assertEquals("test", tb.getSpouse().getName());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:ServletRequestDataBinderTests.java


注:本文中的java.beans.PropertyEditorSupport类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。