I am learning Struts2 and have the following question on submitting a form with Jquery serialize. I have an action class where I have an object called Policy and the policy class has set of fields as shown below. With jquery ajax I want to set a json string in my Action class and would like to deserialize it to an object.
How much ever I try, I am not able to set the string I defined in my action class. Below is the code
Class CassPolicy{
String policyNumber;
String name;
//getsets for members
}
Action:
Class PolicyAction{
String cassPolicyString;
CassPolicy cassPolicy = new CassPolicy();
//getsets for members
String save(){
//In save method I want to convert the policyString to policy object
//policyString always returns null
}
}
JSP:
$.ajax({
url:PolicyAction.action,
type:'post',
data:$("#policyForm").serialize(),
async:true,
success:function(data){
}
});
<s:form id="policyForm">
<s:textfield name="cassPolicy.policyNumber" label="policyNumber"></s:textfield>
<s:textfield name="cassPolicy.name" label="name"></s:textfield>
</s:form>
I even tried in ajax something like data:{cassPolicyString:$("#policyForm).serialize()}
Can someone help me point to the right direction or what is the right way to achieve my task?