Reputation: 1
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.:
onClick
eventsetDealers()
, passing the value, i.e. "reportGroup"
to the action class as shown belowfunction setDealers(){
var rep_value=document.getElementById("reportGroup").value;
alert("Value is"+rep_value);
window.location=="getDealersByGrouppopUpAction?reportGroup="+rep_value;
alert("Just a check")
}
reportGroup
in the action class, i.e. PopUpAction.java
with getters and setters for it.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
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