• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GWT - Capture values of dynamically created components

 
Bhavin B Parekh
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a GWT page with 2 text boxes, 1 hyperlink and 1 button initially (on page load).
When I click on the hyperlink, I add another text box (dynamically without refreshing the page).

Now when I click the button, I need to capture the values that lie in all the three text boxes. How can I do it?

I am desparately looking for some help on this area because I am working on a critical project and badly need help on this.

--
Thanks!
Bhavin
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What have you tried so far, and where are you stuck.

All you need to do is when you create the new text box, hold a reference to it in your code. When the user clicks the button, you can then obtain the text from the text box and process accordingly.
 
Bhavin B Parekh
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, Maneesh.

Yes, I have tried that already but the issue with my scenario is that when I set the Id for any widget, I want to set with some dynamic value rather than just any other Id. And GWT is not allowing me to make use of the reflection API; ccan you please tell me whether GWT allows the usage of Reflection API or not?

--
Thanks!
Bhavin
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reflection! In this scenario? Why? Sounds like an overkill.
Why do you want to play with the id even?

Something this simple is all you really need
 
Bhavin B Parekh
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have pasted my code below.



As you can see, the construction of the entire section is happening inside a for-loop, hence, it is all dynamic. Now, if I just say getText(), I doubt if it'll work out. Can you please provide me some alternate solution to this?
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will still recommend what I suggested in my first reply. Did you try it out?
 
salvin francis
Bartender
Posts: 1268
10
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have posted a huge code thats irrelevant to your actual question.


Here is what i see:



Well my friend, this is not GWT issue, But it's rather a Java 'issue'. Your code logic is to reuse a field variable to point to another object
So Its obvious that you have lost its reference. (Or in simple words, 'txt' will point to the LAST textbox in the loop)

Considering that you are adding some kind of panel on the fly ... you can consider an approach like:



I hope I have solved / correctly understood your problem
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic