2

I created the JS array and try to pass the array to the Controller class, but there it is showing the NullPointerException.

I checked the URL through FireBug there the values are passing but in controller class if I try to retrive it is showing NULL.

JavaScript Code:

var deleteWidgetId = new Array(); //array created 
deleteWidgetId[0] = "a";//adding values 
deleteWidgetId[1] = "b"; 
//action trigged 
$("#saveLayout").load("layout/saveLayout.action", 
 { deleteWidgetId : deleteWidgetId },      
 function(response, status, xhr) { });

Java Code (In controller class):

@RequestMapping(value = "/saveLayout")
public ModelAndView saveLayout(@RequestParam String[] deleteWidgetId) throws Exception { 
    //here that if i try to use the deleteWidgetId it is giving null pointer exception
}
2
  • JavaScript Code: var deleteWidgetId = new Array(); //array created deleteWidgetId[0] = "a";//adding values deleteWidgetId[0] = "b"; //action trigged $("#saveLayout").load("layout/saveLayout.action", { deleteWidgetId : deleteWidgetId }, function(response, status, xhr) { }); Commented Aug 12, 2013 at 12:34
  • Java Code:(In controller class) @RequestMapping(value = "/saveLayout") public ModelAndView saveLayout(@RequestParam String[] deleteWidgetId) throws Exception { //here that if i try to use the deleteWidgetId it is giving null pointer exception } Commented Aug 12, 2013 at 12:35

2 Answers 2

1

Try to use List<String> instead of String[]

Sign up to request clarification or add additional context in comments.

2 Comments

I try this using the List<string> but still it is showing the Null for that deleteWidgetId
Try to rename deleteWidgetId js variable to deleteWidgetIdValues
1

You have to specify the name of the request parameter within the annotation:

@RequestMapping(value = "/saveLayout")
public ModelAndView saveLayout(@RequestParam(value="deleteWidgetId") String[] deleteWidgetId) throws Exception { 
    //here that if i try to use the deleteWidgetId it is giving null pointer exception
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.