ritikavk001
Jul 30th, 2007, 01:06 PM
Hi, I am a newbie to Spring and I am having trouble binding a list of objects.
Here is my code:
public class ECNFeeSchedFormModel {
private ECNFeeSched[] ECNFeeScheds;
//getters and setters
}
public class ECNFeeSched {
private String client_id;
//getters and setters
}
The form controller for the ECNFeeSchedFormModel
public class ECNFeeSchedFormController extends SimpleFormController {
public ECNFeeSchedFormController(){
setCommandName("eCNFeeSchedFormModel");
setCommandClass(ECNFeeSchedFormModel.class);
setFormView("eCNFeeSchedForm");
setSuccessView("eCNFeeSchedFormDone");
}
protected Map referenceData(HttpServletRequest request) throws Exception {
Map reference = new HashMap();
// Put a list of ECNFeeScheds in the requestScope
List eCNFeeScheds = new ArrayList();
eCNFeeScheds.add(new ECNFeeSched("xyz0"));
eCNFeeScheds.add(new ECNFeeSched("xyz1"));
reference.put("ECNFeeScheds", eCNFeeScheds);
return reference;
}
}
In my JSP i have
<form:form commandName="eCNFeeSchedFormModel" name="ECNFeeSchedForm"> <spring:bind path="eCNFeeSchedFormModel.ECNFeeScheds">
<c:forEach items="${requestScope.ECNFeeScheds}" varStatus="varStatus" var="var">
<spring:bind path="eCNFeeSchedFormModel.ECNFeeScheds[${varStatus.index}].client_id">
<input type="text" name="ECNFeeScheds" value="<spring:message text='${var.client_id}'/>" ></input>
</spring:bind>
</c:forEach>
</spring:bind>
<td><input type="submit" name="Submit" value="Submit" /></td>
</form:form>
Also here is how my bean is setup:
<bean name="/eCNFeeSched.htm" class="com.bofa.gcib.gfx.fxpbAdmin.spring.ECNFeeSc hedFormController">
</bean>
Now when I run the app, I get the following exception:
org.springframework.beans.NullValueInNestedPathExc eption: Invalid property 'ECNFeeScheds[0]' of bean class [com.bofa.gcib.gfx.fxpbAdmin.formModel.ECNFeeSchedF ormModel]: Cannot access indexed value of property referenced in indexed property path 'ECNFeeScheds[0]': returned null
I know that LoopTagStatus resolves the index. But I am using JSTL 1.0 and not 1.1. So is this why its not able to resolve the index?
Is there something equivalent in the the http://java.sun.com/jstl/core library?
Without the spring:bind tags.. the values "xyz0" and "xyz1" are displayed in text boxes... however without the binding... its of no use!
Can anyone please help?
Here is my code:
public class ECNFeeSchedFormModel {
private ECNFeeSched[] ECNFeeScheds;
//getters and setters
}
public class ECNFeeSched {
private String client_id;
//getters and setters
}
The form controller for the ECNFeeSchedFormModel
public class ECNFeeSchedFormController extends SimpleFormController {
public ECNFeeSchedFormController(){
setCommandName("eCNFeeSchedFormModel");
setCommandClass(ECNFeeSchedFormModel.class);
setFormView("eCNFeeSchedForm");
setSuccessView("eCNFeeSchedFormDone");
}
protected Map referenceData(HttpServletRequest request) throws Exception {
Map reference = new HashMap();
// Put a list of ECNFeeScheds in the requestScope
List eCNFeeScheds = new ArrayList();
eCNFeeScheds.add(new ECNFeeSched("xyz0"));
eCNFeeScheds.add(new ECNFeeSched("xyz1"));
reference.put("ECNFeeScheds", eCNFeeScheds);
return reference;
}
}
In my JSP i have
<form:form commandName="eCNFeeSchedFormModel" name="ECNFeeSchedForm"> <spring:bind path="eCNFeeSchedFormModel.ECNFeeScheds">
<c:forEach items="${requestScope.ECNFeeScheds}" varStatus="varStatus" var="var">
<spring:bind path="eCNFeeSchedFormModel.ECNFeeScheds[${varStatus.index}].client_id">
<input type="text" name="ECNFeeScheds" value="<spring:message text='${var.client_id}'/>" ></input>
</spring:bind>
</c:forEach>
</spring:bind>
<td><input type="submit" name="Submit" value="Submit" /></td>
</form:form>
Also here is how my bean is setup:
<bean name="/eCNFeeSched.htm" class="com.bofa.gcib.gfx.fxpbAdmin.spring.ECNFeeSc hedFormController">
</bean>
Now when I run the app, I get the following exception:
org.springframework.beans.NullValueInNestedPathExc eption: Invalid property 'ECNFeeScheds[0]' of bean class [com.bofa.gcib.gfx.fxpbAdmin.formModel.ECNFeeSchedF ormModel]: Cannot access indexed value of property referenced in indexed property path 'ECNFeeScheds[0]': returned null
I know that LoopTagStatus resolves the index. But I am using JSTL 1.0 and not 1.1. So is this why its not able to resolve the index?
Is there something equivalent in the the http://java.sun.com/jstl/core library?
Without the spring:bind tags.. the values "xyz0" and "xyz1" are displayed in text boxes... however without the binding... its of no use!
Can anyone please help?