/    Sign up×
Community /Pin to ProfileBookmark

How to access list from child window

Hi,

I’m having trouble accessing a list object from a child window. I’ve used the hidden tag in the parent window to access string variables from the child window, but turning the list into simple strings would be something of a nightmare. Is there a way to do this?

My list of beans is populated from a database and transferred to a form on my jsp page via Struts’ DynaActionForm.

Any help is much appreciated, thanks, Ann.

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@kennyvAug 30.2009 — Ann,

I would need more information in order to help you. But generally it is not to difficult to access something in the parent from a child window.

If you could include some of the html/css code and more details on what you are trying to do I may be able to help you. Also an example of what is being put into the list that you want to access.

Thanks,

Ken

www.webdesigntips-foreveryone.com
Copy linkTweet thisAlerts:
@saustauthorAug 30.2009 — Thanks for reading my message.

Don't know where the limit of too much info is, but here's more details:

The list is a list of products:

public interface Product{

public String getCode();

public String setCode(String code);

public String getName();

public String setName();

}

It gets populated from the database in a class that reads from the database and sets the values displayed in a jsp page:

public final class DisplayAggregateAction

public ActionForward doExecute(

ActionMapping mapping,

ActionForm actionForm,

HttpServletRequest request,

HttpServletResponse response)

throws Exception

{

DynaActionForm form = (DynaActionForm) actionForm;

//Get values from database

List<Product> products = findEligibleProducts(request, user);

form.set("products", products);

form.set("productsSize", products.size());

return new ActionForward(mapping.getInput());

}

The mapping is done in Struts 1.x:

<form-bean

name="aggregateForm"

type="org.apache.struts.action.DynaActionForm">

<form-property name="products" type="java.util.List"/>

<form-property name="productsSize" type="java.lang.Integer"/>

</form-bean>

<action

path="/admin/aggregate"

type="com.struts.reports.DisplayAggregateAction"

name="aggregateForm"

validate="false"

cancellable="true"

input="/admin/aggregate.jsp"

scope="request" >

</action>

And one use for the list in the jsp page is in a drop down list:

<html:form action="/admin/aggregate.do" onsubmit="return false;">

<html:hidden property="productsSize"/>

<tr><td width="50%" align="right" class="label">Product:</td>

<td>

<bean:define id="products" name="aggregateForm" property="products"/>

<html:select property="productCode" onchange="doSwitch();">

<html: options collection="products" property="code" labelProperty="name"/>

</html:select>

</td>

</tr>

</html:form>

Now, I'd like to open a new window and use the list there. I made a JavaScript function in the jsp file that get's called when clicking on a button:

<script language="Javascript">

<!--

function doSwitch()

{

var newWin = window.open("/report_preparation.html", targetName, "toolbar=1,location=1,directory=1,directories=1,status=1,dependent=1,scrollbars=1,resizable=1,width=1024,height=768,top=1,left=1");

newWin.resizeTo(screen.availWidth, screen.availHeight);

newWin.status = 'report being generated...';

newWin.focus();

}

-->

</script>

And I have a function in the report_preparation.html file that reads variables from the parent window. The code below for the integer value works fine, but I can't figure out how to get the product list to the child window.

<SCRIPT language="JavaScript" type="text/javascript">

function getVariable()

{

var size=window.opener.document.forms[0].productsSize.value;

alert("in window " + size);

}

</SCRIPT>

Thanks for reading, Ann.
Copy linkTweet thisAlerts:
@kennyvAug 30.2009 — Ann,

OK, I have a function for you.

I'm not sure exactly where you want to put the options in the select list so I just put them into a variable named listdata and separated each option with a newline.

You could put them into an array or possibly just modify the function to search the list directly.

This should get you started.

function readSelectlist() {

listdata = "";

for (i=0;i<window.opener.document.forms[0].listname.length;i++)

{

listdata = listdata + window.opener.document.forms[0].listname[i].value + "n";

}

alert(listdata);

}



This is what I put in the <body>

<input type="button" onClick="readSelectlist()" value="get list" />

<select name="listname">

<option>option 1</option>

<option>option 2</option>

<option>option 3</option>

<option>option 4</option>

<option>option 5</option>

<option>option 6</option>

<option>option 7</option>

<option>option 8</option>

<option>option 9</option>

<option>option 10</option>

</select>



I haven't tested it in a child window but it should work just fine.



Ken



www.webdesigntips-foreveryone.com
Copy linkTweet thisAlerts:
@saustauthorSep 01.2009 — Thanks for your reply. I can definitely make my code work with your suggestion. However, is there a way to access the underlying list from the child window without using the drop down list?

Ann.
Copy linkTweet thisAlerts:
@kennyvSep 01.2009 — Ann,

I don't really know where the underlying data is coming from.

It sounds to me like you want the select list on the parent window so that is probably the only location of the data.

If you also have it in a javascript array or something you could get it from there or you could have the child window load the data directly.

Good Luck,

Ken

www.webdesigntips-foreveryone.com
Copy linkTweet thisAlerts:
@saustauthorSep 02.2009 — Ken,

you mentioned:

"If you also have it in a javascript array or something you could get it from there"

What would the syntax for that be?

Thanks Ann.
×

Success!

Help @saust spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...