Reputation: 621
var catids = new Array();
I have a catids array where i store the checked checkbox values like the below one.
cat = $("input[name=catChkBox]:checked").map(function () {
return $(this).data('name');
}).get().join(",");
the cat variable forms something like this 1,2,3..
I want to send this "cat" to a java method and print those values.
I pass the values to java through a dwr call like this
DataHandler.getTasks( categories, {callback:function(data){
}, errorHandler:function(){
},async:false
});
I have configured dwr for pojo. should I configure anything for parameters?
I tried the below code but I didn't get anything.
public List<Facade> getTasks(String myIds){
String[] ids = catids .split(",");
System.out.println("-------size of cat id------------" + myIds.length);
for (int i=0; i<myIds.length;i++)
System.out.println(myIds[i]);
//finally it will return a pojo which i l be receiving it in data of dwr call.
-------size of cat id------------ is 1 myIds[i] prints nothing
I need it as an integer back. What mistake am I doing ?
Upvotes: 0
Views: 10303
Reputation: 6516
I will do it in this way.
{"categoryIds": [1,2,3,4,5]}
If you use this solution your code will be more clear and you will be able to share more objects between JavaScript and Java using the same clear solution.
Example (pseudo code)
CategorList class
public class CategoryList {
private ArrayList<Category> categoryList;
// getters and setters
}
Converter
public class CategoryListConverter {
public CategoryList convert(String json) {
Gson g = new Gson();
CategoryList cl = g.fromJson(json, CategoryList.class);
return cl;
}
}
Upvotes: 2
Reputation: 23352
Send this as a form parameter
from webpage. Then get this from HttpServletRequest request
object in java.
request.getParameter('categoryId');
Upvotes: 0
Reputation: 671
I tried the code it workd fine
getTasks("1,2,3");
check what the value of categoriesIds is sent to getTask
Upvotes: 0