Monday 15 March 2010

jquery - Refresh tag on changing backing Java collection in Struts 2 -



jquery - Refresh <s:select> tag on changing backing Java collection in Struts 2 -

i using 2 <s:select> tags , java collection list in list attribute. on alter of 1 want populate sec dropdown. i've used jquery that, it's called action bean , populated list json response when returned , set values in sec drop down. working fine. jquery code shown below.

$(document).ready(function () { $('#projectnamebox').change(function (event) { var projectnameboxval = $("select#projectnamebox").val(); alert(projectnameboxval); $.getjson('getpackagelistaction.action', { "projectid": projectnameboxval }, function (jsonresponse) { alert(jsonresponse); var packagenameselectbox = $('#packagenamebox'); packagenameselectbox.find('option').remove(); $.each(jsonresponse, function (key, value) { $('<option>').val(key).text(value).appendto(packagenameselectbox); }); }); }); });

now concern when updated sec backing list calling action on alter of first, why have utilize below code set alternative data.

var packagenameselectbox = $('#packagenamebox'); packagenameselectbox.find('option').remove(); $.each(jsonresponse, function (key, value) { $('<option>').val(key).text(value).appendto(packagenameselectbox); });

can refresh component reflect changes of backing list ?

the code used modify element of html dom sec select object reflect changes in info model. , if it's double select scenario, should repopulate info sec select , homecoming in json result. pass parameter projectid in ajax phone call should set first select in value attribute when create alternative selection first select box. parameter set action property can utilize repopulate map sec select box. info has been made one-to-many relationship (project <- package), can have different packages single project. 1 time parameter projectid set can query packages belong project id equals bundle projectid. when info sec select box ready homecoming json result serializes property corresponds sec select box json object. should have different action properties each select box. helps limit json output serialize property sec select box. 1 time json returned client need modify dom of sec select box, can't update json received in ajax callback.

you can see question code example: populating 1 select menu based on select menu using ajax in struts2

java jquery jsp select struts2

No comments:

Post a Comment