【发布时间】:2017-10-18 23:05:20
【问题描述】:
在我的 jsp 页面中,我必须将开始日期和到期日期传递到控制器类中。然后使用该日期过滤 Impl 类中的数据。但问题是当将日期传递到控制器时,我还需要显示该数据在引导模式中
这是我在按钮单击这些日期后页面中的 jsp 表单转到控制器类
<table id="default-datatable" data-plugin="DataTable"
class="table table-striped" cellspacing="0"
width="100%">
<thead>
<tr>
<th>Season</th>
<th>Start date</th>
<th>End date</th>
<th>Activate Season</th>
</tr>
</thead>
<tbody>
<c:forEach var="element" items="${seasons}">
<tr>
<form action="season.create" method="POST">
<td>${element.seasonName}</td>
<td>${element.startDate}</td>
<td>${element.endDate}</td>
<%-- <td><a data-toggle="modal"
data-id="${element.seasonId}" title="Add this item"
class="open-AddBookDialog btn btn-info"
href="#myModal">Select Offer</a></td> --%>
<td>
<input type="hidden" name="startDate"
id="startDate" value="${element.startDate}"></input>
<input type="hidden" name="expiryDate"
id="expiryDate" value="${element.endDate}"></input><input type="submit" class="btn btn-primary"
style="width: 90%; margin-top: 10px;"
name="action" value="Add" onclick="showDiv()"></td>
和我的控制器类方法如下所示
@RequestMapping(value = "/season.create", method = RequestMethod.POST)
public String createSeason(@ModelAttribute("Offer") Offer offer, BindingResult result,@RequestParam String action,@RequestParam("startDate") String startDate,
@RequestParam("expiryDate") String expiryDate, Map<String, Object> map, HttpServletRequest request, Model model) {
System.out.println("testing -----------");
int merchantId = 11;
switch (action.toLowerCase()) {
case "add":
offerservice.getAlloffers(merchantId,startDate,expiryDate);
System.out.println("inside season.create test strat date "+startDate+"enddate"+expiryDate);
System.out.println("exDate"+expiryDate);
//map.put("offerFilterd", offerservice.getAlloffers(merchantId));
//map.put("offers", offerservice.getAlloffers(merchantId));
map.put("offers", offerservice.getAlloffers(merchantId,startDate,expiryDate));
map.put("seasons", offerservice.getAllSeasons(merchantId));
map.put("Offer", new Offer());
map.put("SeasonTypes", new SeasonTypes());
map.put("editSingleImage", false);
map.put("imageGalary", false);
map.put("video", false);
break;
case "edit":
break;
case "delete":
break;
case "search":
break;
}
//map.put("offers", offerservice.getAlloffers(merchantId));
map.put("offers", offerservice.getAlloffers(merchantId,startDate,expiryDate));
map.put("seasons", offerservice.getAllSeasons(merchantId));
map.put("Offer", new Offer());
map.put("editSingleImage", false);
map.put("imageGalary", false);
map.put("video", false);
return "create-offer";
}
这是我的 boostrap 模态,包含在 jsp 页面中。
<div id="myModal" class="modal fade" role="dialog" style="display:none;">
<div class="modal-dialog modal-lg">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Select Offer</h4>
</div>
<div class="modal-body">
<div class="table-responsive">
<table id="default-datatable" data-plugin="DataTable"
class="table table-striped" cellspacing="0" width="100%">
<p>form has submitted</p>
<thead>
<tr>
<th>Offer Heading</th>
<th>Offer Description</th>
<th>Issue Date</th>
<th>Expiration date</th>
<th>Offer Discount </th>
<th>Offer Price </th>
<th>Allocated Points </th>
<th>OfferClaim LImit</th>
</tr>
</thead>
<tbody>
<c:forEach var="element" items="${offers}">
<form:form action="offer.bind" method="POST" commandName="SeasonTypes" id="formID">
<tr>
<form:hidden path="seasonId" id="bookId" class="form-control normtxtin"/>
<%-- <td><form:input path="offerId" name="offerid" value="${element.offerid}" class="form-control normtxtin"/></td> --%>
<td>${element.offerSubheading}</td>
<td>${element.offerDescription}</td>
<td>${element.issueDateTime}</td>
<td>${element.expiryDate}</td>
<td>${element.offerDiscount}</td>
<td>${element.offerPrice}</td>
<td>${element.pointsAllocated}</td>
<td>${element.offerClaimLimit}</td>
<td><input type="hidden" id="offerId" name="offerid" type="text" value="${element.offerid}"/></td>
<td><button type="submit" class="btn btn-primary" style="width:100%;font-size:16px;padding:10px;" name="action" value="Add">Select Offer</button></td>
</tr>
</form:form>
</c:forEach>
</tbody>
</table>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
这是我的java脚本代码
<script> function showDiv() { $('#myModal').modal('show') }
</script>
这是我的 DAOIMPL 方法
public List <Offer> getAlloffers(int merchantId,String sDate,String ExDate){
System.out.println("sDate"+sDate+ "EndDate"+ExDate);
Long merchantIdLng = (long) merchantId;
List<Offer> offers= sessionfactory.openSession().createQuery("From Offer where merchant ="+merchantIdLng+"and issueDateTime BETWEEN '"+sDate+"' AND'"+ ExDate+"'" ).list();
return offers;
}
但是点击按钮后它没有显示引导模式。如果有人能说出为什么我的代码不起作用。我需要传递日期并过滤数据并在按钮单击时以模式显示
【问题讨论】:
-
您的具体问题是什么?是你无法打开你的模态还是什么?
-
是的,当按钮单击时我无法打开我的模式,没有表单提交,是否有像 ajax 这样的选项。我想知道如何使用 ajax 完成此操作
-
不需要 ajax 来打开你的模式。 ajax 的用途是从服务器端获取数据。
标签: javascript java jsp