@Override public PropertyEditor getEditor() { return new StringArrayPropertyEditor(); } };
StringArrayPropertyEditor sae = new StringArrayPropertyEditor(); this.defaultEditors.put(String[].class, sae); this.defaultEditors.put(short[].class, sae);
StringArrayPropertyEditor sae = new StringArrayPropertyEditor(); this.defaultEditors.put(String[].class, sae); this.defaultEditors.put(short[].class, sae);
@Test public void withEmptyArrayAsNull() throws Exception { StringArrayPropertyEditor editor = new StringArrayPropertyEditor(",", true); editor.setAsText(""); assertNull(editor.getValue()); }
@Test public void setStringArrayPropertyWithCustomStringDelimiter() throws Exception { PropsTester target = new PropsTester(); AbstractPropertyAccessor accessor = createAccessor(target); accessor.registerCustomEditor(String[].class, "stringArray", new StringArrayPropertyEditor("-")); accessor.setPropertyValue("stringArray", "a1-b2"); assertTrue("stringArray length = 2", target.stringArray.length == 2); assertTrue("correct values", target.stringArray[0].equals("a1") && target.stringArray[1].equals("b2")); }
@Test public void noTrim() throws Exception { StringArrayPropertyEditor editor = new StringArrayPropertyEditor(",",false,false); editor.setAsText(" 0,1 , 2 "); Object value = editor.getValue(); String[] array = (String[]) value; for (int i = 0; i < array.length; ++i) { assertEquals(3, array[i].length()); assertEquals("" + i, array[i].trim()); } assertEquals(" 0,1 , 2 ", editor.getAsText()); }
@Test public void withEmptyArray() throws Exception { StringArrayPropertyEditor editor = new StringArrayPropertyEditor(); editor.setAsText(""); Object value = editor.getValue(); assertTrue(value instanceof String[]); assertEquals(0, ((String[]) value).length); }
@Test public void trimByDefault() throws Exception { StringArrayPropertyEditor editor = new StringArrayPropertyEditor(); editor.setAsText(" 0,1 , 2 "); Object value = editor.getValue(); String[] array = (String[]) value; for (int i = 0; i < array.length; ++i) { assertEquals("" + i, array[i]); } assertEquals("0,1,2", editor.getAsText()); }
@Test public void withCustomSeparator() throws Exception { StringArrayPropertyEditor editor = new StringArrayPropertyEditor(":"); editor.setAsText("0:1:2"); Object value = editor.getValue(); assertTrue(value instanceof String[]); String[] array = (String[]) value; for (int i = 0; i < array.length; ++i) { assertEquals("" + i, array[i]); } assertEquals("0:1:2", editor.getAsText()); }
@Test public void withCharsToDelete() throws Exception { StringArrayPropertyEditor editor = new StringArrayPropertyEditor(",", "\r\n", false); editor.setAsText("0\r,1,\n2"); Object value = editor.getValue(); assertTrue(value instanceof String[]); String[] array = (String[]) value; for (int i = 0; i < array.length; ++i) { assertEquals("" + i, array[i]); } assertEquals("0,1,2", editor.getAsText()); }
@Test public void withDefaultSeparator() throws Exception { StringArrayPropertyEditor editor = new StringArrayPropertyEditor(); editor.setAsText("0,1,2"); Object value = editor.getValue(); assertNotNull(value); assertTrue(value instanceof String[]); String[] array = (String[]) value; for (int i = 0; i < array.length; ++i) { assertEquals("" + i, array[i]); } assertEquals("0,1,2", editor.getAsText()); }
@InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor(String[].class, new StringArrayPropertyEditor(null)); }
StringArrayPropertyEditor sae = new StringArrayPropertyEditor(); this.defaultEditors.put(String[].class, sae); this.defaultEditors.put(short[].class, sae);
@InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor( String[].class, new StringArrayPropertyEditor(null)); }
@InitBinder("choiceList") public void fqBinderInit(WebDataBinder b) { b.registerCustomEditor(String[].class, new StringArrayPropertyEditor("&")); }
StringArrayPropertyEditor sae = new StringArrayPropertyEditor(); this.defaultEditors.put(String[].class, sae); this.defaultEditors.put(short[].class, sae);
this.defaultEditors.put(Properties.class, new PropertiesEditor()); this.defaultEditors.put(Resource[].class, new ResourceArrayPropertyEditor()); this.defaultEditors.put(String[].class, new StringArrayPropertyEditor()); this.defaultEditors.put(URL.class, new URLEditor());