我尝试将 bean 绑定到表单中的表单片段:
[#ftl/]
[#import "spring.ftl" as spring /]
[#import "panda.ftl" as panda /]
[#import "discoveryProject.ftl" as discoveryProject/]
[#macro defineProjectForm newProject]
[@spring.bind "discoveryProjectDetailsBean"/]
[#if newProject?has_content && newProject =="true"]
<table class="transparentTable">
<tr>
<!--Left Part-->
<td>
<table>
<tr>
<td>
[@spring.showErrors " " "errors"/]
<span>Data Source<sup><span style="color: red; ">*</span></sup></span>
</td>
<td>
<select id="dataSourceSelect" onchange="checkSelectChanges()">
[#if discoveryProjectLookupBean.dataSources?has_content]
[#list discoveryProjectLookupBean.dataSources as dataSource]
<option id="${dataSource.id}" value="${dataSource.name}">${dataSource.name}</option>
[/#list]
[/#if]
</select>
[@spring.bind path="discoveryProjectDetailsBean.discoveryProjectBean.dataSource"/]
</td>
</tr>
</table>
这被提交给一个控制器,这个控制器的片段:
@RequestMapping("/navigateDiscoveryProject")
ModelAndView navigateDiscoveryProject(@RequestParam("index")String i,@RequestParam("direction")String direction,
@ModelAttribute("discoveryProjectDetailsBean")DiscoveryProjectDetailsBean discoveryProjectDetailsBean,BindingResult result,HttpSession session)throws Exception{
logger.info("method invoked");
int index=Integer.parseInt(i);
//another code
}
beandiscoveryProjectDetailsBean
包含的属性实际上是另一个 bean,discoveryProjectBean
这个 bean 的属性始终为空,但是我自己在 ftl 中绑定它们,就像上面的 dataSource 属性示例一样,属性的所有值discoveryProjectBean
始终为空。