Chiranjeev Ranjan
Chiranjeev Ranjan

Reputation: 1

Passing a parameter from JSP to action class in Struts 2

I am trying to pass value of a textfield as an URL parameter from a JSP to an action class on clicking of a button (non-submit button) and have found a solution in this link: Onchange event in Struts2.

I have followed all the steps mentioned in that link i.e.:

function setDealers(){
  var rep_value=document.getElementById("reportGroup").value;
  alert("Value is"+rep_value);
  window.location=="getDealersByGrouppopUpAction?reportGroup="+rep_value;
  alert("Just a check")
}

Also to support all this, I have following configuration in struts.xml:

<action name="*popUpAction" class="popUpAction" method="{1}" > 
    <!--this will call a desired method present inside action class --> 
    ...
    ...
</action>

On clicking of the button, getDealersByGroup method of PopUpAction class is supposed to be invoked and use the passed value, i.e. reportGroup in a SQL query. But, as per the above JavaScript function setDealers(), only alert commands are getting executed, and the desired value is not getting passed to the action class.

Is there any thing missing/ or wrong with struts.xml.

Upvotes: 0

Views: 3215

Answers (1)

Roman C
Roman C

Reputation: 1

First, you have made a typo in code == vs =

window.location="getDealersByGrouppopUpAction?reportGroup="+rep_value;

Second, this sounds like redirect to the action, for calling action use s:action or $.ajax() see example.

Trird, for URLs better use s:url tag to build the url.

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

Upvotes: 1

Related Questions