本文整理匯總了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());
}
示例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();
}
};
}
示例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());
}
示例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());
}
示例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());
}
示例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"));
}
示例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"));
}
示例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"));
}
示例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]);
}
示例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]);
}
示例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"));
}
示例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"));
}
示例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"));
}
示例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());
}
示例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());
}