单击复选框到struts操作类时如何发送行值

时间:2017-06-10 06:58:01

标签: jsp struts2

这里我只需要向struts动作类发送选中的值。 如果我检查第一行复选框,那么我只需要向动作类或第4行和第4行值发送1row值

<s:iterator value="stafflistfirsttime">
    <tr >
                                                            <td>second<s:checkbox name="ckeckbox"cssClass="case chkPassport"fieldValue="%{ReferenceID}" /></td>
<td class="t" ><s:property value="ReferenceID" /></td>
<td class="stfnm"><input type='hidden' name="Name" 
value=<s:propertyvalue="teacherFirstName" />" />    
<s:property value="teacherFirstName" /></td>                                                            
<td class="bb"> <s:textfield name="Basics"                                                                  cssClass="form-control expenses" value="" size="6" /></td>
<td class="allw"><div class="form-group">
<div class="col-xs-1"><s:textfield name="Allowances" cssClass="form-control expenses" value="" size="6" /></div></div></td>

2 个答案:

答案 0 :(得分:0)

根据你的小提琴 - 工作fiddle

        <div class="form-group">
           <label class="col-xs-2 control-label">Month</label>
           <div class="col-xs-3">
              <s:select headerKey="" headerValue="--Select--"
                 list="#{'1':'JAN', '2':'FEB', '3':'MAR','4':'APR','5':'MAY','6':'JUN','7':'JUL', '8':'AUG', '9':'SEP', '10':'OCT','11':'NOV', '12':'Dec'}"
                 name="selctmonth" cssClass="form-control" />
           </div>
           <label class="col-xs-1 control-label">Year</label>
           <div class="col-xs-3">
              <div class="input-group input-append date" id="yearPicker">
                 <s:textfield name="selctyear" cssClass="form-control"
                    id="yearofExam" />
                 <span class="input-group-addon add-on"><span
                    class="glyphicon glyphicon-calendar"></span></span>
              </div>
           </div>
           <div class="col-xs-1">
              <s:submit cssClass="btn btn-primary" value="Search" />
           </div>
        </div>
        <div id="row_dim">
        <div class="dataTable_wrapper">
           <table class="table table-bordered display nowrap"
              id="dataTS">
              <thead>
                 <tr>
                    <th style="background: #00a8a8; color: white;"></th>
                    <th style="background: #00a8a8; color: white;">Reference
                       id
                    </th>
                    <th style="background: #00a8a8; color: white;">Employee
                       name
                    </th>
                    <th style="background: #00a8a8; color: white;">Month</th>
                    <th style="background: #00a8a8; color: white;">Year</th>
                    <th style="background: #00a8a8; color: white;">Basics</th>
                    <th style="background: #00a8a8; color: white;">Allowances</th>
                    <th style="background: #00a8a8; color: white;">Edit</th>
                    <th style="background: #00a8a8; color: white;">Submit</th>
                 </tr>
              </thead>
              <tbody>
                 <s:iterator value="firsttime">
                 <tr id="ReferenceID_1">
                    <td> <input type="checkbox" name="age" value="1" /></td>
                    <td class="t ReferenceID"> 1</td>
                    <td class="stfnm">
                       <s:property
                          value="ffff" />
                    </td>
                    <td class="mnt">
                       <div class="form-group">
                          <div class="col-xs-2">
                             <s:select id="Name"
                                list="#{'1':'01', '2':'02', '3':'03','4':'04','5':'05','6':'06','7':'07', '8':'08', '9':'09', '10':'10','11':'11', '12':'12'}"
                                name="selctmonth" cssClass="form-control" />
                          </div>
                       </div>
                    </td>
                    <td class="yr">
                       <h5 class="yearforpay"></h5>
                    </td>
                    <td class="bb"> <input type="text" name="allowance"
                       class="form-control expenses" value="" size="6" />
                    </td>
                    <td class="netsalary"><input
                       class="form-control expenses_sum" size="6"></td>
                    <td class="wday">
                       <s:property value="TableID" />
                    </td>
                    <td>Unpaid</td>
                 </tr>
                 <tr id="ReferenceID_2">
                    <td> <input type="checkbox" name="age" value="2" /></td>
                    <td class="t ReferenceID">2</td>
                    <td class="stfnm">
                       <s:property
                          value="ffff" />
                    </td>
                    <td class="mnt">
                       <div class="form-group">
                          <div class="col-xs-2">
                             <s:select id="Name"
                                list="#{'1':'01', '2':'02', '3':'03','4':'04','5':'05','6':'06','7':'07', '8':'08', '9':'09', '10':'10','11':'11', '12':'12'}"
                                name="selctmonth" cssClass="form-control" />
                          </div>
                       </div>
                    </td>
                    <td class="yr">
                       <h5 class="yearforpay"></h5>
                    </td>
                    <td class="bb"> <input type="text" name="allowance"
                       class="form-control expenses" value="" size="6" />
                    </td>
                    <td class="netsalary"><input
                       class="form-control expenses_sum" size="6"></td>
                    <td class="wday">
                       <s:property value="TableID" />
                    </td>
                    <td>Unpaid</td>
                    <td>
           </table>
        </div>
        <br>
        <br>
        <button type="button"
           class="btn btn-info use-address1 submitbtn">Submit</button></td>
        <!-- Modal 2 -->
        <div class="modal fade" id="myModal" role="dialog">
           <div class="modal-dialog">
              Modal content
              <div class="modal-content">
                 <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                 </div>
                 <div class="modal-content">
                    <div class="modal-header">
                       <button type="button" class="close" data-dismiss="modal"
                          id="closeMark">&times;</button>
                    </div>
                    <div class="modal-body">
                       <div class="form-group">
                          <label class="col-xs-3 control-label">Reference</label>
                          <div class="col-xs-5 ">
                             <input type='text' name="examDate1" class="form-control"
                                id="Referenceid"/> 
                          </div>
                       </div>
                       <br>  
                       <div class="form-group">
                          <label class="col-xs-3 control-label">Allowance</label>
                          <div class="col-xs-5 ">
                             <input type='text' name="examDate1" class="form-control" id="allowanceid"
                                /> 
                          </div>
                       </div>
                       <div align="center">
                          <button type="submit" class="btn btn-primary updatemodul"
                             >Update</button>
                       </div>
                    </div>
                    <div class="modal-footer">
                       <button type="button" class="btn btn-default"
                          data-dismiss="modal" id="modalReset">Close</button>
                    </div>
                 </div>
              </div>
           </div>
        </div>
        <!-- Trigger the modal with a button -->


<script>

        $(document).on("click", ".editbuttton", function() {
            var RecordId = $(this).closest("tr").find(".ReferenceID").text();
            $("#myModal #Referenceid").val(RecordId);


        });
        $(document).on("click", ".submitbtn", function() {

            jsonObj = [];
            var chboxCheck = false;
            $('#dataTS').find('input[type="checkbox"]:checked').each(function() {
                chboxCheck = true;
                var $this = $(this);
                var ClosestTr = $this.closest("tr");
                var Employeename = ClosestTr.find(".stfnm").html();
                var EmployeeId = $this.val();
                item = {}
                item["EmployeeId"] = EmployeeId;
                item["Employeename"] = Employeename;
                jsonObj.push(item);

            });
            console.log(jsonObj);
            if (!chboxCheck) {
                alert("please check atleat one checkboc");
                return false;
            }
            $.ajax({
                type: 'POST',
                url: 'submitonebyonestaff',
                dataType: 'JSON',
                data: jsonObj,
                success: function(data, success) {
                    console.log(data);
                }
            });
        });

        var ReferenceAllow = '';
        $(".updatemodul").click(function() {
            ReferenceAllow = $("#allowanceid").val();
            console.log(ReferenceAllow);
            $.ajax({
                type: 'POST',
                url: 'submitonebyonestaff',
                dataType: 'JSON',
                data: {


                },

                success: function(data, success) {
                    console.log(ReferenceAllow);
                    var ReferenceID = 1;
                    var UpdateHtml = "<td>" + ReferenceID + "</td><td></td></td><td></td><td></td><td></td><td><td class='netsalary'><input class='form-control expenses_sum Test' size='6' value='" + ReferenceAllow + "'></td><td></td><td></td><td>Test</td>";
                    $(document).find("#ReferenceID_" + ReferenceID).empty().append(UpdateHtml);
                    $('#myModal').modal('hide');


                    alert("sucess")

                },
                error: function(data, error) {
                    alert("error")

                }

            });

        });


</script>

答案 1 :(得分:0)

用普通的html

替换现有的标签
<checkbox name="ckeckbox"class="case chkPassport"value="${ReferenceID}" />

由于struts请求包装器,应该可以从valueStack访问ReferenceID