0

我正在尝试为对象列表创建复选框列表。在我的表单支持 bean 中,我有 2 个列表。一份包含我所有组织的参考数据列表。将包含所选组织的另一个列表。

我的页面加载正常,但是当我尝试提交时,出现以下异常:

 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 列表和一个条目。当我选择多个复选框时,它会崩溃....

4

1 回答 1

1

在你的jsp中,在你犯了一个小错误的forEach标签中,它应该是var="organization"而不是var="${organization}"

于 2012-12-03T13:12:29.943 回答