I have read many posts on this subject however, I have yet to see a solution to the problem. How do I bind an indexed property of ArrayList type with a custom object that contains properties I need set? I have found most developers bind to a single property but, I need the flexiblity to set multiple properties on my model object.
For example...
I have a FormAction that contains a model object in flow scope; Address which looks like this:
The Resident class looks like this:Code:public class Address { private String address1; private String address2; private String city; private String state; private Integer zip; private ArrayList<Resident> residents = new ArrayList<Resident>(); ... All Getters & Setters here...
Application context (address.xml) looks like this:Code:public class Resident { private String firstName; private String lastName; ... All Getters & Setters here...
My flow definition looks like this:Code:<bean id="addressFormAction" class="org.springframework.webflow.action.FormAction"> <property name="formObjectName" value="address" /> <property name="formObjectClass" value="com.briskoe.model.Address" /> <property name="formObjectScope" value="FLOW" /> </bean>
I am executing this flow through a test case which looks like this:Code:<flow start-state="showNewAddressForm"> <view-state id="showNewAddressForm" view="addressForm"> <entry-actions> <action bean="addressFormAction" method="setupForm"/> </entry-actions> <transition to="confirmAddressChange" on="submit"> <action bean="addressFormAction" method="bind" /> </transition> </view-state> <view-state id="confirmAddressChange" view="confirmAddressChangeForm"> <transition to="complete" on="submit" /> </view-state> <end-state id="complete" view="thankYou" /> <import resource="address.xml"/> </flow>
public class AddressFlowTest extends AbstractXmlFlowExecutionTests {
The test case fails on signalEvent("submit"...) complaining about an Index Out of Bounds, which I suspected was caused by the binding not occurring correctly:Code:@Override protected ExternalizedFlowDefinition getFlowDefinition() { return new ExternalizedFlowDefinition("address-flow", new ClassPathResource("com/briskoe/address-flow.xml")); } public void testAddressFlow() { final ApplicationView appView = (ApplicationView) startFlow(); assertCurrentStateEquals("showNewAddressForm"); final HashMap formData = new HashMap(); formData.put("address1", "1 Infinite Loop"); formData.put("address2", "Suite 200"); formData.put("city", "Cupertino"); formData.put("state", "CA"); formData.put("zip", "90210"); formData.put("residents[0].firstName", "Apple"); signalEvent("submit", new ParameterMap(formData)); assertCurrentStateEquals("confirmAddressChange"); assertModelAttributeNotNull("address", appView); final Address address = (Address)appView.getModel().get("address"); assertEquals(1, address.getResidents().size()); } }
Has anyone tried to accomplish what I am and if so how did you do it?Code:org.springframework.webflow.ActionExecutionException: Exception thrown executing [AnnotatedAction@1c74f37 targetAction = org.springframework.webflow.action.FormAction@641e9a, attributes = map['method' -> 'bind']] in state 'showNewAddressForm' of flow 'address-flow' -- action execution properties where 'map['method' -> 'bind']'; nested exception is org.springframework.beans.InvalidPropertyException: Invalid property 'residents[0]' of bean class [com.briskoe.model.Address]: Index of out of bounds in property path 'residents[0]'; nested exception is java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 Caused by: org.springframework.beans.InvalidPropertyException: Invalid property 'residents[0]' of bean class [com.briskoe.model.Address]: Index of out of bounds in property path 'residents[0]'; nested exception is java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0


Reply With Quote
