Collection/List property won't bind or update

2019-04-12 13:13发布

问题:

So I have set up a wizard interface with spring web flow that gradually populates a single form object/model. It works fine for the first few steps that have to populate single String or primitive properties and a String array (from a checkbox interface).

Then I have a List<String> property. It renders properly as multiple textboxes with correct initialized values. But when I edit the textboxes on the browser and submit, the values do not take effect on the form bean. It still has the initial values.

Below is the detailed set-up:

Web flow on-start which creates the bean:

<on-start>
    <evaluate expression="new mypackage.MyFormBean()" result="flowScope.myFormBean" />
</on-start>

Here are the relevant parts of my form bean:

public class MyFormBean implements Serializable {
    ...
    private List<SlotBean> slots;
    ...
    public List<SlotBean> getSlots() {
        return slots;
    }
    public void setSlots(List<SlotBean> slots) {
        this.slots= slots;
    }
    ...
}

public class SlotBean {
    ...
    private int quantity;
    ...
    public int getQuantity() {
        return quantity;
    }
    public void setQuantity(int quantity) {
        this.quantity= quantity;
    }
    ...
}

I have a series of view-states in my web flow with simple string or number field bindings set-up that are initialized, displayed and saved without issues to the form.

This view-state generates any number of SlotBean objects then initializes quantity with 2. These are set to the slots property.

<view-state id="generate-criteria" model="disciplineCatalogue">
    ...
    <transition on="next" to="slots-grid">
        <evaluate expression="myService.generateSlots(myFormBean)"/>
    </transition>
    ...
</view-state>

Here is the jsp fragment. All it does is render a bunch of textboxes. There's also a next button:

<form:form id="slotsGrid" modelAttribute="myFormBean" action="${flowExecutionUrl}">
    ...
    <c:forEach var="slot" items="${myFormBean.slots}" varStatus="idx">
        <form:input path="slots[${idx.index}].quantity" />
    </c:forEach>
    ...
    <button type="submit" id="next" name="_eventId_next">Next</button>
    ...
</form:form>

The above code displays correctly with the initial values (2). It generates multiple textboxes like below:

<input id="slots0.quantity" name="slots[0].quantity" type="text" value="2"/>

So when this page is on the browser, I change the values of the quantity textboxes to different values and click the "next" button. On my browser's network debugger, I see that the form values are sent to the server:

slots[0].quantity:3
slots[1].quantity:1
slots[2].quantity:2

Here is the relevant web flow entry for the next button.

<view-state id="slots-grid" model="myFormBean">
    <binder>
        ...
        <binding property="slots" />
    </binder>
    ...
    <transition on="next" to="finished">
        <evaluate expression="myService.create(myFormBean)"/>
    </transition>
    ...
</view-state>

So I put a break point on the myService.create(myFormBean) method and it shows that all the quantity fields are still set to the original "2". The new values didn't bind to myFormBean.slots.

Is there anything you can see in my set-up that looks wrong?

Thanks for any time you can put into this

Spring Framework 3.1.1

Spring-Webflow 2.3.1

Tomcat 6.0.18

Eclipse Indigo

Cross-posted in: http://forum.springsource.org/showthread.php?127809-Collection-List-property-won-t-bind-or-update-on-form-submit