Link to home
Start Free TrialLog in
Avatar of rmvprasad
rmvprasad

asked on

Pop up using struts

I am new to struts. I need to generate a popup window and pass values to it using struts.

I found the following code on net

javascript function onclick="passSelected()"

<input type="hidden" name="selectedItem" value=""/>


function passSelected(var)
{
      alert(var);
      var url='popup.do?selectedItem='+var;
      window.open('url','New','height=600,width=600',200,200);
}

My doubt is how to pass this selected item as a parameter to popup.do. in the above function it is passing as a url. Can I directly access this in the action class. or do I need to use some statement as
 
req.getParameter("selectedItem") in the action class.
Avatar of girionis
girionis
Flag of Greece image

> My doubt is how to pass this selected item as a parameter to popup.do

You can do

onclick="passSelected(this.yourformname.selectedItem.value)" and this should get you the value in the input with the name "selectedItem"
Avatar of rmvprasad
rmvprasad

ASKER

Thoe I am using a form data is not accessed through form as it is stored in valueobjects/transferobjects which is declared inside the form. Data is displayed in table not in controls as textbox

will not the statement req.getParameter("selecteditem" ) declared in action class work.
> Data is displayed in table not in controls as textbox

Then you will need ot fill the value using other means, something like

javascript function onclick="passSelected()"

function passSelected()
{
      alert(var);
      var url='popup.do?selectedItem='+<%=<your struts variable here>%>;
      window.open('url','New','height=600,width=600',200,200);
}

> will not the statement req.getParameter("selecteditem" ) declared in action class work.

This will use the request object. You could use that as well by doing

javascript function onclick="passSelected()"

function passSelected()
{
      alert(var);
      var url='popup.do?selectedItem='+<%=req.getParameter("selecteditem" )%>;
      window.open('url','New','height=600,width=600',200,200);
}

but you will have to set the "selectedItem" value from a *previous* page.
Thanks for the real good answer. One last question

Will the statement

var url='popup.do?selectedItem='+<%=req.getParameter("selecteditem" )%>;

pass the value of the selected item to popup.do, as I need it in popup.do. If no how to.
ASKER CERTIFIED SOLUTION
Avatar of girionis
girionis
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial