This week's book giveaway is in the General Computing forum.
We're giving away four copies of Learning Regular Expressions and have Ben Forta on-line!
See this thread for details.
Win a copy of Learning Regular Expressions this week in the General Computing 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

GWT - Capture values of dynamically created components  RSS feed

 
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
 
Bartender
Posts: 11445
18
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
Bartender
Posts: 11445
18
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
Bartender
Posts: 11445
18
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?
 
Bartender
Posts: 1879
50
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!