java如何在SpringWebFlow中将多个模型绑定到一个视图?
情况:我正在开发一个spring MVC webapp,并使用spring web flow和tiles框架。我在DBcustomer
和customerAdress
中有两个表,我为它们命名了两个模型类customerModel
和customerAdressModel
现在在我的流程中。xml我有以下view-state
<var name = "cust" class = "com.model.CustomerModel"/>
<view-state id = "customerViewState" view = "customer" model = "cust">
<transition on="next" to="customerData"/>
</view-state>
Tile framework将视图customer
解析为相应的customer.jsp
,如下所示:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<div>
<form id="Form" method="post" enctype="multipart/form-data" class="form-
inline">
<div class="inputDiv">
<label class="inputLabel"> Name :</label>
<input type="text" name="name" id="name">
<label class="inputLabel">Email :</label>
<input type="email" name="email" id="email">
</div>
<input type="button" id="forwardButton" value="Next"/>
</form>
</div>
</body>
<script>
$("#forwardButton").click(function(){
$("#WlDetailsForm").attr('action','${flowExecutionUrl}&_eventId=next');
$("#WlDetailsForm").submit();
});
</script>
</html>
问题:现在customer.jsp
中指定的表单有一些包含customerAdressModel
属性值的输入字段。因此,我想将customerModel
以及customerAdressModel
绑定到相同的视图状态customerViewState
。我该怎么做,我查了spring DOC但什么都找不到,请帮忙
注意:我不能修改我的sql表
# 1 楼答案
可以创建复合模型DTO
并将其用作视图状态模型
更新
对于视图,我建议使用Spring的表单标签库。定义标记库
并将jsp中的表单替换为