|
From: Shishir K. S. <sk...@sy...> - 2004-07-01 02:38:59
|
Hello,=20
I have a simple form=20
----------------------------------------
public class TestForm {
private Boolean testBoolean; =20
private String[] arrayOne;
private String[] arrayTwo;
=20
public TestForm() {}
=20
public String[] getArrayOne() {
return this.arrayOne;
}
public void setArrayOne(String[] arrayOne) {
this.arrayOne =3D arrayOne;
}
public String[] getArrayTwo() {
return this.arrayTwo;
}
public void setArrayTwo(String[] arrayTwo) {
this.arrayTwo =3D arrayTwo;
}
public Boolean getTestBoolean() {
return this.testBoolean;
}
public void setTestBoolean(Boolean testBoolean) {
this.testBoolean =3D testBoolean;
}
}
---------------------------------------------
And my test case is :
---------------------------------------------
public void testBindWithInitializer() throws ServletException {
=20
ServletContext sc =3D new MockServletContext();
MockHttpServletRequest request =3D new =
MockHttpServletRequest(sc);
=20
request.addParameter("testBoolean", "true");
request.addParameter("arrayTwo", "arraytwo_1,arraytwo_2");
TestForm form =3D new TestForm();
Errors errors =3D BindUtils.bind(request,form, "form", new
BindInitializer() {
public void initBinder(ServletRequest request,
ServletRequestDataBinder binder) {
=20
binder.registerCustomEditor(String[].class,"arrayTwo",new
StringArrayPropertyEditor());
}
});
=20
assertTrue("arraytwo length", form.getArrayTwo().length =3D=3D =
2);
=20
}
--------------------------------------------------------
I am trying to add a custom editor for a particular attribute by
specifying the attributeName "arrayTwo" on the registerCustomBinder
However, I get the following error:
Testcase: testBindWithInitializer took 0.12 sec
Caused an ERROR
Invalid property 'arrayTwo[0]' of bean class [com.test.TestForm]: Cannot
access indexed value of property referenced in indexed property path
'arrayTwo[0]': returned null
org.springframework.beans.NullValueInNestedPathException: Invalid
property 'arrayTwo[0]' of bean class [com.test.TestForm]: Cannot access
indexed value of property referenced in indexed property path
'arrayTwo[0]': returned null
at
org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperIm
pl.java:499)
at
org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperIm
pl.java:484)
at
org.springframework.beans.BeanWrapperImpl.getPropertyType(BeanWrapperImp
l.java:917)
at
org.springframework.validation.BindException.resolveMessageCodes(BindExc
eption.java:162)
at
org.springframework.validation.DataBinder.bind(DataBinder.java:229)
at
org.springframework.web.bind.ServletRequestDataBinder.bind(ServletReques
tDataBinder.java:92)
at
org.springframework.web.bind.BindUtils.bind(BindUtils.java:65)
at com.test.TestMail.testBindWithInitializer(TestMail.java:82)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
a:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor
Impl.java:25)
at
junit.extensions.TestDecorator.basicRun(TestDecorator.java:22)
at junit.extensions.TestSetup$1.protect(TestSetup.java:19)
at junit.extensions.TestSetup.run(TestSetup.java:23)
at
org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAnt
Runner.java:377)
at
org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAn
tRunner.java:135)
It works fine (as expected) if I remove the attribute. Am I doing
something wrong/missing something ?
Thanks
Shishir=20
|