Having an issue with JSON data being sent through AJAX from the client side. The data is showing as null inside my action class.
Here is the JSON string:
{"data":[{"id":"","col":1,"row":1,"size_x":1,"size_y":1},
{"id":"","col":1,"row":2,"size_x":1,"size_y":1},
{"id":"","col":1,"row":3,"size_x":1,"size_y":1},
{"id":"","col":1,"row":4,"size_x":1,"size_y":1},
{"id":"","col":1,"row":6,"size_x":1,"size_y":1},
{"id":"","col":1,"row":5,"size_x":1,"size_y":1}
]
}
AJAX setup:
var seats = {"data" : positions};
var seatPosition = JSON.stringify(seats);
console.log(seatPosition);
$.ajax({
url: 'retrieve-seat',
data: seatPosition,
dataType: 'json',
contentType: 'application/json',
type: 'POST',
async: true,
success: function (data) {
alert("success");
Configuring in struts.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<constant name="struts.action.extension" value="," />
<constant name="struts.enable.SlashesInActionNames" value="true" />
<constant name="struts.custom.i18n.resources" value="global" />
<package name="default" namespace="/"
extends="json-default,struts-default">
<action name="retrieve-seat" class="com.pointwest.apex.actions.ReadPositionAction">
<result name="SUCCESS" type="json"/>
</action>
</package>
</struts>
Action class implementation:
public class ReadPositionAction extends ActionSupport {
private List<Seat> data;
public List<Seat> getData() {
System.out.println("Getter Call");
return data;
}
public void setData(List<Seat> data) {
System.out.println("Setter Call");
this.data = data;
}
@Override
public String execute() {
System.out.println("action");
try {
System.out.println(data);
System.out.println("Execute Method");
} catch (Exception e) {
e.printStackTrace();
}
return "SUCCESS";
}
}
The JSON format appears to be correct based on the console log. Any assistance would be greatly appreciated. Thank you!