This question is very similar to this one:
Collection/List property won't bind or update on form submit
What i am trying to do is map a set of Checkboxes within a JSP to a Map within a webflow. Binding for example Strings to the model works totally fine. However, the map does not. Here is some example code:
The Model:
public class MyForm {
private String selectedOrderBy;
private Map<String, boolean> selected = new HashMap<>();
private List<MyClass> items = new ArrayList<>();
//Now setters and getters for the members
}
public MyClass {
private String hash = "<some hash>"; //plus getter and setter
}
The flow:
<flow xmlns="http://www.springframework.org/schema/webflow"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/webflow
http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
<var name="model" class="MyForm"/>
<var name="selectedOrderBy" class="java.lang.String"/>
<view-state id="selection" model="model">
<binder>
<binding property="selectedOrderBy"/>
<binding property="selected"/>
</binder>
<transition on="submit" to="saveSelection"/>
</view-state>
<action-state id="saveSelection">
<evaluate expression="MyService.saveSelection(model, externalContext.nativeRequest)"/>
<transition to="selection"/>
</action-state>
</flow>
The JSP:
<form:form modelAttribute="model" method="post" enctype="application/x-www-form-urlencoded" acceptCharset="utf-8">
...here is some more code including a selectbox mapping to selectOrderBy...
<table>
<c:foreach items="${model.items}" var="item">
<tr><td>
<form:checkbox path="selected['${item.hash}']" value="true"/>
...
</td></tr>
</c:foreach>
</table>
</form:form>
And finally the Service:
@Named
public class MyService {
public void saveSelection(MyForm model, HttpServletRequest request){...}
}
The checkboxes successfully display the values found in the map. However, on submit, the changed values are not bound to the model (while the String "selectOrderBy" works). So i debugged into MyService#saveSelection, and i found that the map in the model still has the old values. At the same time, the new values are actually in the request.
So for the moment, I manually extract them from the request:
String selected = request.getParameter("selected['" + hash + "']");
But this is some pretty ugly workaround. Does anybody have a clue why this is the case?
Greetings,
Sascha.