0

I am trying to call a method in action class in javascript function on button click event which is in jsp.I am using struts 2.could you tell me how to do this? There is a function in ListAlgorithmAction Class which I want to call when the user clicks submit button.

function alertselected (){
    var x = document.getElementById ( "select_name" ).selectedIndex;
    var y = document.getElementById ( "select_name" ).options;
    var id = y [x].index;
    redirect(id);
}

function redirect(x){
    document.getElementById ( "param_ID" ).value = x;
    document.forms ["./ListAlgorithmAction"].submit ();
}

Pigueiras
  • 18,778
  • 10
  • 64
  • 87
Soham
  • 91
  • 2
  • 6
  • 15

2 Answers2

3

I do not think this is something related to Struts2 ,since struts2 is independent of the way you call action class be it by java-script form submit,ajax or by simple form submit.

i believe you have some form in your jsp like

<s:form action="myAction" name="myForm">
  some data

</s:form>

on click you can do something like

function redirect(x){
    document.getElementById("param_ID").value=x;
    document.myForm.action="ListAlgorithmAction";
     document.myForm.submit();
    }

This is just solution based on your inputs and there can be many more if you able to define your problem more

Umesh Awasthi
  • 23,407
  • 37
  • 132
  • 204
  • Thanks for you reply man..:) But I was just looking out how to call a method in Action class by passing param_ID as one of the parameter. – Soham Aug 30 '12 at 21:53
  • so what's difficult passing a parameter? is there any issue? and i already told you it dependents upon how you want to pass the values and how you want to call it – Umesh Awasthi Aug 31 '12 at 05:17
  • Iam struggling with how to pass my form variables to action class, your solution solves to me, Thanking you +1 – Naveen Kumar Alone Aug 21 '13 at 13:57
0

For similar implementations we used to use http://directwebremoting.org/dwr/index.html (DWR). You can try that.. if you have big implementation i would suggest you to integrate this framework

KD.
  • 2,015
  • 3
  • 28
  • 59