spring - spring web flow使用复选框绑定对象列表

  显示原文与译文双语对照的内容
0 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 ( 对象对象) 方法。 当我尝试提交时,我不会传递 toObject ( 。字符串代码,对象对象对象),因为在它之前发生了异常。

英镑笔记:当我只选择一个复选框时,一切都很正常。 我可以看到我的支持bean包含一个带有一个条目的selectedOrganisations列表。 当我选择多个复选框而不是它崩溃时。

时间: 原作者:

0 0

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

原作者:
...