This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • 0
  • 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";
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • 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
  • 0
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • 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
  • 0
  • 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.
 
Brent Sterling
Ranch Hand
Posts: 948
  • 0
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic