Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

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

 
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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";
 
Marshal
Posts: 67425
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no such thing as ArrayList in JavaScript. Of what are you actually speaking?
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 67425
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
You are HERE! The other map is obviously wrong. Better confirm with this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic