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












2















Trying to pass the list of selected subjects to Controller, but the bean is not receiving the list of subjects.



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.










share|improve this question

























  • To shorten how about using $("form").on("submit") and $(this).serialize()

    – mplungjan
    Nov 15 '18 at 7:46











  • understood. but will that solve problem?

    – SHAIK BAJI VALI
    Nov 15 '18 at 7:50











  • Simplification is always good. Any errors in console or app log?

    – mplungjan
    Nov 15 '18 at 8:00











  • No error messages in console

    – SHAIK BAJI VALI
    Nov 15 '18 at 8:32











  • it just need to store the elements in the jtable in to array and append it to the data field.

    – SHAIK BAJI VALI
    Nov 15 '18 at 8:33
















2















Trying to pass the list of selected subjects to Controller, but the bean is not receiving the list of subjects.



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.










share|improve this question

























  • To shorten how about using $("form").on("submit") and $(this).serialize()

    – mplungjan
    Nov 15 '18 at 7:46











  • understood. but will that solve problem?

    – SHAIK BAJI VALI
    Nov 15 '18 at 7:50











  • Simplification is always good. Any errors in console or app log?

    – mplungjan
    Nov 15 '18 at 8:00











  • No error messages in console

    – SHAIK BAJI VALI
    Nov 15 '18 at 8:32











  • it just need to store the elements in the jtable in to array and append it to the data field.

    – SHAIK BAJI VALI
    Nov 15 '18 at 8:33














2












2








2








Trying to pass the list of selected subjects to Controller, but the bean is not receiving the list of subjects.



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.










share|improve this question
















Trying to pass the list of selected subjects to Controller, but the bean is not receiving the list of subjects.



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.







javascript jquery spring-mvc jquery-ui






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 7:45









mplungjan

87.6k21124181




87.6k21124181










asked Nov 15 '18 at 7:30









SHAIK BAJI VALISHAIK BAJI VALI

266




266













  • To shorten how about using $("form").on("submit") and $(this).serialize()

    – mplungjan
    Nov 15 '18 at 7:46











  • understood. but will that solve problem?

    – SHAIK BAJI VALI
    Nov 15 '18 at 7:50











  • Simplification is always good. Any errors in console or app log?

    – mplungjan
    Nov 15 '18 at 8:00











  • No error messages in console

    – SHAIK BAJI VALI
    Nov 15 '18 at 8:32











  • it just need to store the elements in the jtable in to array and append it to the data field.

    – SHAIK BAJI VALI
    Nov 15 '18 at 8:33



















  • To shorten how about using $("form").on("submit") and $(this).serialize()

    – mplungjan
    Nov 15 '18 at 7:46











  • understood. but will that solve problem?

    – SHAIK BAJI VALI
    Nov 15 '18 at 7:50











  • Simplification is always good. Any errors in console or app log?

    – mplungjan
    Nov 15 '18 at 8:00











  • No error messages in console

    – SHAIK BAJI VALI
    Nov 15 '18 at 8:32











  • it just need to store the elements in the jtable in to array and append it to the data field.

    – SHAIK BAJI VALI
    Nov 15 '18 at 8:33

















To shorten how about using $("form").on("submit") and $(this).serialize()

– mplungjan
Nov 15 '18 at 7:46





To shorten how about using $("form").on("submit") and $(this).serialize()

– mplungjan
Nov 15 '18 at 7:46













understood. but will that solve problem?

– SHAIK BAJI VALI
Nov 15 '18 at 7:50





understood. but will that solve problem?

– SHAIK BAJI VALI
Nov 15 '18 at 7:50













Simplification is always good. Any errors in console or app log?

– mplungjan
Nov 15 '18 at 8:00





Simplification is always good. Any errors in console or app log?

– mplungjan
Nov 15 '18 at 8:00













No error messages in console

– SHAIK BAJI VALI
Nov 15 '18 at 8:32





No error messages in console

– SHAIK BAJI VALI
Nov 15 '18 at 8:32













it just need to store the elements in the jtable in to array and append it to the data field.

– SHAIK BAJI VALI
Nov 15 '18 at 8:33





it just need to store the elements in the jtable in to array and append it to the data field.

– SHAIK BAJI VALI
Nov 15 '18 at 8:33












2 Answers
2






active

oldest

votes


















1














By default, jQuery supports json format submissions



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






share|improve this answer


























  • thanks for the answer. Can you be more specific like where should i put this and which lines has to be replaced?

    – SHAIK BAJI VALI
    Nov 15 '18 at 9:59











  • var data = { 'firstName':$("#firstNameInCreateStudent").val()), ......... 'studentSubjects': selSubjectIds } data :data

    – Z KK
    Nov 16 '18 at 9:55













  • that was helpful. thanks

    – SHAIK BAJI VALI
    Nov 20 '18 at 11:29



















0















Thanks to Everyone for your efforts.I found my self a way to solve
this as Follows




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". Then i used StringTokenizer to
seperate each id and parsed each id from string type to int.







share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53314394%2fpass-the-list-of-checked-values-to-controller-by-bean-object%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    By default, jQuery supports json format submissions



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






    share|improve this answer


























    • thanks for the answer. Can you be more specific like where should i put this and which lines has to be replaced?

      – SHAIK BAJI VALI
      Nov 15 '18 at 9:59











    • var data = { 'firstName':$("#firstNameInCreateStudent").val()), ......... 'studentSubjects': selSubjectIds } data :data

      – Z KK
      Nov 16 '18 at 9:55













    • that was helpful. thanks

      – SHAIK BAJI VALI
      Nov 20 '18 at 11:29
















    1














    By default, jQuery supports json format submissions



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






    share|improve this answer


























    • thanks for the answer. Can you be more specific like where should i put this and which lines has to be replaced?

      – SHAIK BAJI VALI
      Nov 15 '18 at 9:59











    • var data = { 'firstName':$("#firstNameInCreateStudent").val()), ......... 'studentSubjects': selSubjectIds } data :data

      – Z KK
      Nov 16 '18 at 9:55













    • that was helpful. thanks

      – SHAIK BAJI VALI
      Nov 20 '18 at 11:29














    1












    1








    1







    By default, jQuery supports json format submissions



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






    share|improve this answer















    By default, jQuery supports json format submissions



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







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 15 '18 at 10:24









    Saeed Zhiany

    1,57441624




    1,57441624










    answered Nov 15 '18 at 9:51









    Z KKZ KK

    111




    111













    • thanks for the answer. Can you be more specific like where should i put this and which lines has to be replaced?

      – SHAIK BAJI VALI
      Nov 15 '18 at 9:59











    • var data = { 'firstName':$("#firstNameInCreateStudent").val()), ......... 'studentSubjects': selSubjectIds } data :data

      – Z KK
      Nov 16 '18 at 9:55













    • that was helpful. thanks

      – SHAIK BAJI VALI
      Nov 20 '18 at 11:29



















    • thanks for the answer. Can you be more specific like where should i put this and which lines has to be replaced?

      – SHAIK BAJI VALI
      Nov 15 '18 at 9:59











    • var data = { 'firstName':$("#firstNameInCreateStudent").val()), ......... 'studentSubjects': selSubjectIds } data :data

      – Z KK
      Nov 16 '18 at 9:55













    • that was helpful. thanks

      – SHAIK BAJI VALI
      Nov 20 '18 at 11:29

















    thanks for the answer. Can you be more specific like where should i put this and which lines has to be replaced?

    – SHAIK BAJI VALI
    Nov 15 '18 at 9:59





    thanks for the answer. Can you be more specific like where should i put this and which lines has to be replaced?

    – SHAIK BAJI VALI
    Nov 15 '18 at 9:59













    var data = { 'firstName':$("#firstNameInCreateStudent").val()), ......... 'studentSubjects': selSubjectIds } data :data

    – Z KK
    Nov 16 '18 at 9:55







    var data = { 'firstName':$("#firstNameInCreateStudent").val()), ......... 'studentSubjects': selSubjectIds } data :data

    – Z KK
    Nov 16 '18 at 9:55















    that was helpful. thanks

    – SHAIK BAJI VALI
    Nov 20 '18 at 11:29





    that was helpful. thanks

    – SHAIK BAJI VALI
    Nov 20 '18 at 11:29













    0















    Thanks to Everyone for your efforts.I found my self a way to solve
    this as Follows




    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". Then i used StringTokenizer to
    seperate each id and parsed each id from string type to int.







    share|improve this answer




























      0















      Thanks to Everyone for your efforts.I found my self a way to solve
      this as Follows




      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". Then i used StringTokenizer to
      seperate each id and parsed each id from string type to int.







      share|improve this answer


























        0












        0








        0








        Thanks to Everyone for your efforts.I found my self a way to solve
        this as Follows




        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". Then i used StringTokenizer to
        seperate each id and parsed each id from string type to int.







        share|improve this answer














        Thanks to Everyone for your efforts.I found my self a way to solve
        this as Follows




        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". Then i used StringTokenizer to
        seperate each id and parsed each id from string type to int.








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 16 '18 at 10:20









        SHAIK BAJI VALISHAIK BAJI VALI

        266




        266






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53314394%2fpass-the-list-of-checked-values-to-controller-by-bean-object%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Tangent Lines Diagram Along Smooth Curve

            Yusuf al-Mu'taman ibn Hud

            Zucchini