根据用户选择的值从下拉列表生成Jasper报告(有两个下拉列表)。
JSP:
<form:form name="f" action="${flowExecutionUrl}" modelAttribute="simpleReportSelector">
<table class="search">
<tr><th colspan="3"><fmt:message key="report.someextract"/></th></tr>
<tr>
<td><b><fmt:message key="somereport.sortdate"/></b>
<select id="firstfield" name="localDate" onchange="this.form.reloadPage.value='true';submit()">
<c:forEach var="dl" items="${dateList}">
<c:if test="${dl.selected==false}">
<option value="${dl.itemValue}">${dl.itemLabel}</option>
</c:if>
<c:if test="${dl.selected==true}">
<option selected="selected" value="${dl.itemValue}">${dl.itemLabel}</option>
</c:if>
</c:forEach>
</select>
</td>
<td><input type="hidden" id="reloadPage" name="reloadPage" value=""/></td>
<td><b><fmt:message key="somereport.equipNumber"/></b>
<select id="uld" name="uldNumber">
<c:forEach var="u" items="${uldList}">
<option value="${u.itemValue}">${u.itemLabel}</option>
</c:forEach>
</select>
</td>
</tr>
<tr><td class="right" colspan="3"><button type="submit" name="_eventId_exportReport">Submit</button></td></tr>
<tr class="hide">
<td><input id="submithidden" type="submit" value="submithidden" name="_eventId_submitButton" /></td>
</tr>
</table>
</form:form>
当用户从标题中选择此特定菜单时,页面会填充datelist
和uldlist
。 datelist
默认为今天日期,uldlist
默认为“选择”。当用户选择上一个日期或将来的日期时,uldlist
应填充不同的列表。
控制器:
@Controller
@RequestMapping("/uldReport.do")
public class ULDReport {
@Transactional(readOnly=true)
@RequestMapping(value="/uldReport.do",method = RequestMethod.GET)
public String setupForm(Model model, HttpServletRequest request, HttpServletResponse response) {
//code to populate datelist and uld list(populates using present day)
}
@Transactional(readOnly=true)
@RequestMapping(params={"reloadPage='true'"}, value="/uldReport.do", method = RequestMethod.GET)
public String setUpUld(Model model, HttpServletRequest request, HttpServletResponse response) {
//this should populate the uld list by using the date seelcted by user
}
@Transactional(readOnly=true)
@RequestMapping(params={"reloadPage='false'"}, method = RequestMethod.POST)
public ModelAndView processSubmit(@ModelAttribute SimpleReportSelector simpleReportSelector, Model model, HttpServletRequest request, HttpServletResponse response) throws IOException{
//some code
}
}
第一种方法效果很好,但是当我更改日期时,app会指向错误页面。我认为可能是@RequestMapping
的内容,如果我从控制器中的第二个和第三个方法中移除params
,则应用processandsubmit
提交。我做错了什么?
答案 0 :(得分:1)
由于URL的构造方式,可能会发生这种情况。页面加载空白页面这一事实意味着它无法找到符合您设置标准的任何内容,因此它会默默地失败。
为了让它按预期工作,您可能需要将网址格式化为:
/uldReport.do?reloadPage=true
或
/uldReport.do/reloadPage/true
取决于您的设置。
但关键是它需要在URL中,而不是表单中提交的字段,现在看起来就好了。