samedi 27 juin 2015

.ajax with Struts2

I have done some major refactoring and changed some plugins to an existing project. A previously working ajax call to an action class does not work. The action class's variables are not being set. I have checked FireBug to see that the POST variables are there and they are the same as before the changes were made.

Here is the code in my jsp:

var dataToSend;
dataToSend= $("#form").serializeArray();
$.ajax({
    type : "POST",
    url : "updateList",
    data : dataToSend,
    success : function(data) { ...

Here's my class/method

String[] firstName;
String[] lastName;

public String testPerson() {
    String returnStr = null;
    for (String x : firstName){
        System.out.println(x);
        if(x.equals("Tom"){
            returnStr = x;
        }
    }
    return returnStr
}

public String[] getFirstName() {
    return firstName;
}

public void setFirstName(String[] firstName) {
    this.firstName = firstName;
}

public String[] getLastName() {
    return lastName;
}

public void setLastName(String[] lastName) {
    this.lastName = LastName;
}

The array firstName is null when it should be populated. Is there anything else I should check? The struts2-json plugin matches the struts2 version.

Aucun commentaire:

Enregistrer un commentaire