當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。