Solved

Pop up using struts

Posted on 2006-07-04
5
668 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
ID: 17037715
> 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
ID: 17037815
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
ID: 17037863
> 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
ID: 17037917
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
ID: 17037935
> 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Why my table column Id is not passed to java object? 4 44
Configure a Bean in an XML file 4 42
servlet example 17 51
What's wrong with this code? 4 26
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Online promotion is consistently becoming more important for all types of businesses. From Facebook ads to search engines to YouTube videos, there are all sorts of channels that can effectively be used to promote a business or product. But how shoul…
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

860 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