简体   繁体   English

通过Bean对象将已检查值列表传递给控制器​​?

[英]Pass the list of checked values to controller by Bean object?

Trying to pass the list of selected subjects to Controller, but the bean is not receiving the list of subjects. 尝试将所选主题列表传递给Controller,但bean没有收到主题列表。

Here's the code that I'm trying: 这是我正在尝试的代码:

$("#submitCreateStudent").click(function() {
      var selSubjectIds = new Array();
      $('#subjectsTableInCreateStudent').find('.jtable-data-row').each(function() {
        if (selSubjectIds.length < 1) {
          selSubjectIds.push($(this).attr('data-record-key') + '$');
        } else {
          selSubjectIds += $(this).attr('data-record-key') + '$';
        }
      });

      if (validateCreateStudentForm()) {

        var data = new FormData();
        data.append('firstName', $("#firstNameInCreateStudent").val());
        data.append('lastName', $("#lastNameInCreateStudent").val());
        data.append('address', $("#studentAddressInCreateStudent").val());
        data.append('collegeName', $("#studentCollegeNameInCreateStudent").val());
        data.append('phoneNumber', $("#phoneNumberInCreateStudent").val());
        data.append('email', $("#emailInCreateStudent").val());
        data.append('studentDepartment', $("#departmentInCreateStudent").val());
        data.append('studentBranch', $("#branchInCreateStudent").val());
        data.append('DateOfBirth', $("#dobInCreateStudent").val());
        data.append('DateOfReport', $("#dorInCreateStudent").val());
        data.append('loginUserName', $("#studentUserNameInCreateStudent").val());
        data.append('loginPassword', $("#passwordInCreateStudent").val());
        data.append('studentSubjects', selSubjectIds);

        //                        data.append('skipInitialTraining', skipInitialTraining);

        $("#maskingId").mask("Saving...");

        $.ajax({
          url: "AddStudent.do",
          data: data,
          //                           
          //Remaining code goes here.
        });
      });

All the details are coming to controller class except for the list of subjects which are selected check boxes. 除了选中复选框的主题列表外,所有细节都将进入控制器类。

By default, jQuery supports json format submissions 默认情况下,jQuery支持json格式提交

data :{'selSubjectIds':selSubjectIds} or $(this).serialize(); data :{'selSubjectIds':selSubjectIds}$(this).serialize();

Thanks to Everyone for your efforts.I found my self a way to solve this as Follows 感谢Everyone的努力。我发现自己是一个解决这个问题的方法

var arr = "";
$('#subjectsTableInCreateStudent').find('.jtable-data-row').each(function() {
                        var record = $(this).data('record');
                        arr += record.subjectId + seperatorForGridCells;   

                    });

Here the arr variable stores every ID as a String by concating with Some seperator "seperatorForGridCells". 这里,arr变量通过与Some seperator“seperatorForGridCells”进行仲裁,将每个ID存储为String。 Then i used StringTokenizer to seperate each id and parsed each id from string type to int. 然后我使用StringTokenizer来分隔每个id并将每个id从string类型解析为int。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM