Thursday, 15 July 2010

javascript - Passing a parameter from JSP to action class in Struts 2 -



javascript - Passing a parameter from JSP to action class in Struts 2 -

i trying pass value of text-field url parameter jsp action class on clicking of button(non-submit button) , have found solution in link: onchange event in struts2.

i have followed steps mentioned in link i.e.:

creating javascript function onclick event inside function i.e. setdealers, passing value i.e. "reportgroup" action class shown below class="lang-js prettyprint-override">function setdealers(){ var rep_value=document.getelementbyid("reportgroup").value; alert("value is"+rep_value); window.location=="getdealersbygrouppopupaction?reportgroup="+rep_value; alert("just check") } created variable name "reportgroup" in action class i.e. popupaction.java getters , setters it.

also back upwards this, have next configuration in struts.xml:

class="lang-xml prettyprint-override"><action name="*popupaction" class="popupaction" method="{1}" > <!--this phone call desired method nowadays within action class --> ... ... </action>

on clicking of button, getdealersbygroup method of popupaction class supposed invoked , utilize passed value i.e. "reportgroup" in sql query. per above javascript function setdealers alert commands getting executed , desired value not getting passed action class.

is there thing missing/ or wrong struts.xml.

first, have made typo in code == vs =

window.location="getdealersbygrouppopupaction?reportgroup="+rep_value;

second, sounds redirect action, calling action utilize s:action or $.ajax() see example.

trird, urls improve utilize s:url tag build url.

var url = "<s:url action='getdealersbygrouppopupaction'/>"+"?reportgroup="+rep_value; window.location=url;

javascript jsp struts2

No comments:

Post a Comment