使用jsp并使用确认风

时间:2016-02-27 15:01:46

标签: jsp foreach jstl

我真的需要帮助,我想从我的数据库中删除一行,但每次点击删除按钮时它只会删除表格中的第一个元素。点击链接到" #myModal"(风将apear),变量p.getIdUser()将包含第一个元素的id,而不是所选的一个,而我把这个块进入" foreach"避免丢失p.getIdUser()。这是我的代码。

file.jsp   

<c:forEach items="${liste}" var="p" >
                   <tr>
                       <td>${p.getIdUser()}</td>
                       <td>${p.getNom()}</td>
                       <td>${p.getPrenom()}</td>
                       <td>${p.getCin()}</td>
                       <td>${p.getPassword()}</td>   
                       <td>${p.getDateEnt()}</td> 
                       <td>${p.getGrade()}</td> 
                       <td>${p.getEmail()}</td> 
                       <td>${p.getTel()}</td> 
                       <td>${p.getAdr()}</td> 
                       <td>${p.getRole()}</td> 
                       <td>${p.getCodeSite()}</td> 
                       <td> <a href="user.html"><i class="fa fa-pencil"></i></a>
                           <a href="#myModal" role="button" data-toggle="modal">${p.getIdUser()}<i class="fa fa-trash-o"></i></a></td>                         
                    </tr>

                    <div class="modal small fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                         <div class="modal-dialog">
                            <div class="modal-content">
                                          <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                                            <h3 id="myModalLabel">Delete Confirmation</h3>
                                           </div>
                                 <div class="modal-body">
                                    <p class="error-text"><i class="fa fa-warning modal-icon"></i>Are you sure you want to delete the user?<br>This cannot be undone.</p>
                                 </div>
                                 <div class="modal-footer">
                                    <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Cancel</button>
                                     <a href='DeleteUser?id=${p.getIdUser()}'> <button class="btn btn-danger">Delete</button></a>
                                 </div>
                              </div>
                        </div>
                    </div>
</c:forEach>         

1 个答案:

答案 0 :(得分:0)

使用模态弹出窗口旁边的forloop,因为你在for循环中使用模态弹出窗口所以没有创建具有相同名称的模态弹出窗口,或者当你单击执行任务时你的上一个模型弹出窗口打开---

这样做.........从Shouting Code找到解决方案       调用Js函数(带参数userId)在model-popup中设置模型userId 解决方案:

<c:forEach items="${emailBatchList}" var="emailBatchVar"
   varStatus="statusVar">
   <pg:item>
      <tr>
         <td>${emailBatchVar.date }</td>
         <td>${emailBatchVar.campaignType }</td>
         <td>${emailBatchVar.campaignName }</td>
         <td>${emailBatchVar.noOfEmailsSent }</td>
         <td>${emailBatchVar.deliveryStatus }</td>
         <td>${emailBatchVar.successfullyDelivered }</td>
         <td>${emailBatchVar.sentBy }</td>
         <td>${emailBatchVar.timeOfDispatch }</td>
         <td>
            <div class="deliveryDetail${statusVar.count}"
               hidden="hidden">${emailBatchVar.deliveryDetails}</div>
            <a data-toggle="modal" data-target="#viewDetails"
               onclick="campaignReport(${statusVar.count});"> <i
               class="fa fa-area-chart fa-lg btn-view"></i>
            </a>
         </td>
      </tr>
   </pg:item>
</c:forEach>


<!-- Modal PopUp Div For Delivery Details-->
<div id="viewDetails" class="modal fade adjust-modal"
   role="dialog">
   <div class="modal-dialog">
      <!-- Modal content-->
      <div class="modal-content">
         <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal"
               aria-label="Close">
            <span aria-hidden="true">×</span>
            </button>
            <h4 class="modal-title" id="myModalLabel">Delivery
               Details
            </h4>
         </div>
         <div class="modal-body">
            <!-- Content start -->
            <div class="tab-content emailReport">
               <!--  content will be added dynamicaly -->
            </div>
            <!-- Content end -->
         </div>
         <div class="modal-footer">
            <button type="button" class="btn btn-default"
               data-dismiss="modal">Close</button>
         </div>
      </div>
   </div>
</div>
<!-- Modal Popup Div (view-details) end -->

JS

function campaignReport(index) {
    $('.tab-content').empty();
    var deliveryDetail = $.parseJSON($('.deliveryDetail'+index).text());
    var tabContent = '';
    if(deliveryDetail != null && deliveryDetail != '')
    {  
        tabContent = '<div class="row"><div class="col-sm-6"><div class="table-responsive"><table class="table">'
            +'<tr><td>Requested Mails:</td><td>'+deliveryDetail['requests']
        +'</td></tr><tr><td>Deliverd Mails:</td><td>'+deliveryDetail['delivered']+'</td></tr><tr><td>'
        +'Blocked Mails:</td><td>'+deliveryDetail['blocks']+'</td></tr><tr><td>'
        +'Bounced Mails:</td><td>'+(deliveryDetail['bounces']+deliveryDetail['bounce_drops'])
        +'</td></tr><tr><td>'
        +'Spam Mails:</td><td>'+(deliveryDetail['spam_reports']+deliveryDetail['spam_report_drops'])
        +'</td></tr><tr><td>'
        +'Invalid Mails:</td><td>'+deliveryDetail['invalid_emails']+'</td></tr>'
        +'</table></div></div></div>';
        $('.tab-content.emailReport').append(tabContent);
    }
}