Announcement Announcement Module
No announcement yet.
Command object & List field binding issue Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Command object & List field binding issue


    I've an interesting situation here.

    JSP form containing several check boxes each representing a store.
    A user can select any no. of stores to group them.

    When user submits the form those selected check box's objects(i.e. the stores) should be available in a command object's List field.

    e.g. List<stores> storesAssociated

    I'm not currently getting the List object in the form controller. My code is as below.
    FormController: -

    public class MyFormController extends SimpleFormController {

    public ModelAndView onSubmit(HttpServletRequest request,
    HttpServletResponse response,
    Object command,
    BindException errors) throws ServletException{

    StoresGroup storesGroup = (StoresGroup)command;

    List<Store> stores = storesGroup.getStoresAssociated();

    return new ModelAndView(new RedirectView(getSuccessView()));

    protected Object formBackingObject(HttpServletRequest request) throws ServletException{

    StoresGroup storesGroup = new StoresGroup();

    return storesGroup;


    protected Map referenceData(HttpServletRequest request) throws Exception {

    Map<String, Object> map = new HashMap<String, Object>();

    List<Brand> brands = brandsDAOImpl.getBrandsList();

    List<Store> storesAssociated = storesDAOImpl.getStoresList();

    map.put("brands", brands);

    map.put("storesAssociated", storesAssociated);

    return map;


    ============ Command Class =========

    public class StoresGroup {

    private String name;
    private List<Store> storesAssociated;

    protected final Log logger = LogFactory.getLog(getClass());

    public String getName() {
    return name;
    public void setName(String name) { = name;
    public List<Store> getStoresAssociated() {
    return storesAssociated;
    public void setStoresAssociated(List<Store> storesAssociated) {
    this.storesAssociated = storesAssociated;


    ============ JSP ===========
    <c:when test="${not empty storesAssociated}">

    <c:forEach var="store" items="${storesAssociated}" varStatus="loopStatus">
    <td height="20" class="labelSmall"><form:checkbox path="storesAssociated" label="${}" value="${store}" ></form:checkbox></td>
    <td align="left"><c: out value="${}"/></td>
    <c: otherwise><c: out value="No Stores"/></c: otherwise>

    But I'm not able to get the check box selected stores after Form Submit's.
    Please suggest me what's going wrong.


    I'm really stuck with this, does check boxes and binding using path attribute create such a problem... Community, please suggest me a solution...
    Last edited by beginner; Jun 11th, 2008, 09:53 AM. Reason: Emphasize