aspose file tools*
The moose likes Struts and the fly likes How to set a property's value thats part of a ArrayList using Javascript. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to set a property Watch "How to set a property New topic
Author

How to set a property's value thats part of a ArrayList using Javascript.

Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
To set the name property in a form we can simply specify

document.forms[0].name="javaranch";


But how to set the same name property thats part of a class thats inside an ArrayList which is
in a form?


This doesn't work

document.forms[0].namesList.nameClass.name="javaranch";


Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

There is no such thing as ArrayList in JavaScript. Of what are you actually speaking?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
My form bean object has an arraylist (or) simply list property like


class MyForm extends ActionForm {

private List name;
private String department;

}

We can directly set the department property in javascript like

document.forms[0].department="production";

But name property contains a bunch of objects(since it is a ArrayList (or) List) of type EmployeeName class which has the property myName of String type.

class EmployeeName {
String myName;
}

I am using indexed properties to iterate through the name List and display the myName property in my JSP page.

For one particular scenario I need to set the myName property via Javascript.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Beans exist on the server. JavaScript has no access to them. To get data to the server you'll need to submit the value.
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
Thanks for your response Bear.

Here is my requirement.

Using indexed properties I iterate through the name List and assign myName property to a textbox in my JSP page.

Adjacent to the textbox I have a link which opens a pop-up window, which has a textbox and a submit button. On click of submit button the value entered in the textbox should come and sit in the parent windows textbox.

If the parent windows textbox property is in the parent form as a String setting is simple and straight forward.

Example:
document.forms[0].department="production";

But in my case the property is in a bean object which I iterate dynamically.

I don't know how to get the value from pop-up window to parent window. Can you please suggest me a way out.
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
On the server-side you might have "bean objects" but in the browser you just have html with form fields. If you look at the source of the generated html the property name for the text boxes is probably something like "name[2].myName".

- Brent
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to set a property's value thats part of a ArrayList using Javascript.