samedi 25 juin 2016

x-editable submit additional "array" to the total AJax POST data


I'm trying to add an array of object to the post data of a group of bootstrap x-editable in my jsp page.

I recover the data from a table, and build an array of object. After do that, I need to append this array to the list of the other value posted by the editables in the page.

I've an html table with id="user" and this code recover data from it and build the array of object. This is my code, that works and produces the correct object:

function recover_data() {
    console.log("Starting recover");
    var beneficiary_list = [];
      $('.lav').each(function() {
        var obj = {'company': $(this).attr('id'), 'num':$(this).text() };
        beneficiary_list.push(obj)   
      });
    console.log(beneficiary_list); //output to check array produced             
    return beneficiary_list;
};

this function is what I call from a save button, that launch my global submit retrieving data from all editable in the page and adding in the "params" the array returned from recover_data(), in this way:

jQuery('#data a').editable('submit',{
        url:'test/prove/data_received',
        params: function(params) {
            params.beneficiary = recover_data();
            return params;
        }, 
        success:function(resp){  ... }

  })

but testing with Postman (Chrome) the produced output to POST, is without the array. Are submitted only the "editables" data, but no "beneficiary" field with array of that values adding. The missing field must be like

"beneficiary": [0: company: "1", num: "22" ..etc..]

How can I "append" to the produced POST data from a group of editables an array of objects, like that I've show?

Looking to this page is possible

Question on github x-editable page

I don't understand why don't works...I follow the example written on second post from vitalets, he wrote:

editable({
...
params: function(params) {
    params.checked = ... //get array of checked values
    return params;
}
});

To Explain better what I need: I've a Java Controller (servlet) that receive a modelView object (POJO) with several fields (that came from other editables in the page) and a field "ArrayList beneficiary" where Beneficiary is a small object of two fields "company" and "num"

public Class Beneficiary{
    private String company;
    private String num;

   //then get e set methods..
} 

instead, my POJO is like:

import java.util.ArrayList;
import Beneficiary;

public class Module {

    private Integer id;
    private String titolo;
    private String companyRating;
    private ArrayList<Beneficiary> beneficiary;


    //get e set methods

In the console I obtain the correct object for that voice

capture from console

but not in the post object that is like

incorrect post

instead I need that the produced output "beneficiaries" field to POST url is something similar to this example (found on internet)

correct

How can I obtain a list of that object from my JSP page when submit? Someone can help me?


Aucun commentaire:

Enregistrer un commentaire