Solved

Pop up using struts

Posted on 2006-07-04
5
664 Views
Last Modified: 2013-11-28
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.
0
Comment
Question by:rmvprasad
  • 3
  • 2
5 Comments
 
LVL 35

Expert Comment

by:girionis
Comment Utility
> 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"
0
 

Author Comment

by:rmvprasad
Comment Utility
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.
0
 
LVL 35

Expert Comment

by:girionis
Comment Utility
> 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.
0
 

Author Comment

by:rmvprasad
Comment Utility
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.
0
 
LVL 35

Accepted Solution

by:
girionis earned 50 total points
Comment Utility
> pass the value of the selected item to popup.do, as I need it in popup.do

It will if the parameter "selectedItem" comes from a *previous* page (i.e. when you did the request), if in the same page as the JavaScript code you have a "selectedItem" parameter and you want to get this then you will not be able to do it using the "req" object. You will have to use JavaScript.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Digital marketing agencies have encountered both the opportunities and difficulties that emerge from working with a wide-ranging organizations.
Read about the 3 stages of the buyer's journey: awareness, consideration, and decision.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now