• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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";
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic