This should be basics but I'm having trouble with posting multiple parameters from dojo on a rest endpoint. I have the following method on my back end exposed via resteasy.
@POST()
@Path("/updateProduct")
@Consumes(MediaType.APPLICATION_JSON)
public void updateGeneralSettings(String session,Product product) {
System.out.println("session"+session);
System.out.println("product"+product.toString);
}
This works perfectly fine just with Product as the parameter. I'm yet to figure out how to build a jason string with another parameter. Product data just binding from form and this is some additional parameter I wanted to attach with it (i.e. session).
jsonData = dojo.toJson(product)
var handler = request.post(url, {
data: jsonData,
headers: {
"Content-Type": 'application/json; charset=utf-8',
"Accept": "application/json"
}
});
Appreciate if you guys can give me some solution.
Try adding parameter names to your method signature:
public void updateGeneralSettings(@FormParam("session") String session, @FormParam("product") Product product)
and then something like:
var handler = request.post(url, {
data: {
session: session,
product: jsonData
},
headers: {
"Content-Type": 'application/json; charset=utf-8',
"Accept": "application/json"
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With