[I tried to simplifie the code to better understand the questions]When I
tried to send data from a web side client to an ActionClass in Struts 2
like:

CLIENT SIDE:
-----------------------------------------
    jQuery("#bedata").click(function(){ //Function for button "bedata"

     var postData = "SOME DATA TO SEND"

    //Sendin data:
    $.ajax({
        type: "POST", //Method to send the data. I would need "post" method
as better option.
        url: "GuardaFila.action", //Action called to data treatament
        data : {
            jgGridData: postData, //PARAMETER jgGrdData with variable
"postData" value
            customData: "someinfo" //Just another parameter called
"customData" with more data,
        },


    /** START: handlers for request. Not important for this trouble **/
        dataType:"json",
        contentType: "application/json; charset=utf-8",
        success: function(response, textStatus, xhr) {
            alert("success");
         },
        error: function(xhr, textStatus, errorThrown) {
            alert("error");
        }
    /** END: handlers for the request. **/
    });
    });


----------


I wanted to autofill "jgGridData" and "customData" attributes from
ActionClass that is called when "CargaTabla.action" is invoked. But if type
is POST, it doesnt work.
Just changing POST type in ajax type of sending, turning on "GET", it works
fine. The call to CargaTabla.action ActionClass setters methods for the
jgGridData and customData has done properly.



SERVER SIDE:
My struts.xml piece of significant code is:

    <action name="GuardaFila" method="guardarUsuario"
class="org.json.JSONRespuestaTabla">
        <result name="success" type="json" />
    </action>

So, GuardaFila action in its method "guardarUsuario" is properly called in
debuggin. A simplified version of ActionClass (org.json.JSONRespuestaTabla)
is:

public class JSONRespuestaTabla extends ActionSupport{

    String jgGridData = "Old data to be refilled from client";
    String customData = "Old data to be refilled from client";

    @Override
    public String execute() {
        //Some stuff
        return SUCCESS;
    }

    //Getters and Setter of attributes.

    public void setJgGridData(String resultado){
        System.out.append(resultado);
    }
    public String getJgGridData(){
        return this.jgGridData
    }
    public String getCustomData() {
        return customData;
    }
    public void setCustomData(String customData) {
        this.customData = customData;
    }

    //And the method called and defined in struts.xml (properly called)
    public void guardarUsuario(){
       //Some stuff.
       return;
    }

Well, so. If Javascript send the parameters in GET mode, SETTERS are
working nice, and I can get "SOME DATA TO SEND" on my ActionClass
JSONRespuestaTabla setted automatically, ready to work with. But if
JavaScript sends this data in POST mode, Struts doesnt call the setters,
and I am not able to recieve the data into the class that handle the action.

How it comes that? I cant understand why it happens.

I am using jquery, json and tiles plugin for struts2.

Thank you for your help.

Reply via email to