views:

382

answers:

1

So I have a table in a jsp page with several rows and checkboxes for each row. I created a js function that creates an array of the value on the checkboxes. I want to send this array over in an ajax call so I toJson-ed it but I dont understand how actionbean variables get set with these parameters. Can anyone help? THANKS!

+1  A: 

Good question. Typically you create instance variables on your action beans, expose w/ getter/setters, and they are populated automagically via form post params or get params.

If you had a small handful of checkboxes, you could make a boolean for each one on your ActionBean, then your ajax call could be to a URL like "Preferences.action?box1=true&box2=false&box3=false".

If you had a ton, you could create a List on the ActionBean. I've only dealt w/ this the non-ajax way, but you'd set the name attribute on the checkbox to something like this: name="preferences[0]". I think you could do a jquery ajax call this way too, but you might have to url encode the name of the param.

I think you could also look into the jquery form plugin to simply POST the json over.

lucas