2012-11-30 69 views
0

我想創建一個對象列表複選框的列表。 在我的表單支持bean中,我有2個列表。一個包含所有組織的參考數據的列表。另一個列表將包含選定的組織。春季webFlow綁定與複選框的對象列表

我的頁面加載罰款,但是當我嘗試提交我得到以下異常:

Caused by: javax.servlet.ServletException: javax.servlet.jsp.JspTagException: No message found under code 'typeMismatch on selectedOrganizations' for locale 'nl'. 
    at org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:852) 
    at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781) 
    at org.apache.jsp.WEB_002dINF.views.flows.validation_jsp._jspService(validation_jsp.java:177) 
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369) 
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:322) 
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:249) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:638) 
    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:543) 
    at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:480) 
    at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:968) 
    at org.apache.jsp.tag.web.wizard_tag._jspx_meth_form_005fform_005f0(wizard_tag.java:198) 
    at org.apache.jsp.tag.web.wizard_tag.doTag(wizard_tag.java:146) 
    at org.apache.jsp.WEB_002dINF.views.management.roleinvitation.create.selectOrganizations_jsp._jspx_meth_iam_005fwizard_005f0(selectOrganizations_jsp.java:375) 
    at org.apache.jsp.WEB_002dINF.views.management.roleinvitation.create.selectOrganizations_jsp._jspService(selectOrganizations_jsp.java:141) 
    ... 126 more 

找到我的代碼片段在這裏:

JSP

<c:forEach items="${organizations}" var="${organization}"> 
    <form:checkbox cssClass="organizationCheckbox" path="selectedOrganizations" value="${organization}"/> 
</c:forEach> 

查看型號

public class CreateRoleInvitationViewModel implements Serializable { 
    private List<OrganizationViewModel> selectedOrganizations; 
    private List<OrganizationViewModel> organizations; 
... 
} 

轉換

public class StringToOrganizationViewModel extends StringToObject { 

    public StringToOrganizationViewModel() { 
    super(OrganizationViewModel.class); 
    } 

    @Override 
    protected Object toObject(String code, Class targetClass) throws Exception { 
    OrganizationViewModel orgViewModel = new OrganizationViewModel(); 
    orgViewModel.setCode(code); 
    return orgViewModel; 
    } 

    @Override 
    protected String toString(Object object) throws Exception { 
    return ((OrganizationViewModel)object).getCode(); 
    } 

} 

如果使用轉換器,它是用來我檢查。當我的頁面被加載時,我傳遞了toString(Object object)方法。 當我嘗試提交時,我沒有傳遞toObject(String code,Object objectClass),因爲它之前發生了異常。

注意:當我只選擇一個複選框..一切工作正常。我可以看到我的支持bean包含一個帶有一個條目的selectedOrganisations列表。當我選擇多個複選框比它崩潰....

在JSP

回答

1

,在foreach標記你犯了一個小錯誤,應該是var="organization"而不是var="${organization}"