File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes GWT and the fly likes GWT - Capture values of dynamically created components Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » GWT
Bookmark "GWT - Capture values of dynamically created components" Watch "GWT - Capture values of dynamically created components" New topic
Author

GWT - Capture values of dynamically created components

Bhavin B Parekh
Greenhorn

Joined: Mar 19, 2008
Posts: 8
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

Joined: Jul 26, 2007
Posts: 9990
    
    7

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.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Bhavin B Parekh
Greenhorn

Joined: Mar 19, 2008
Posts: 8
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

Joined: Jul 26, 2007
Posts: 9990
    
    7

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

Joined: Mar 19, 2008
Posts: 8
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

Joined: Jul 26, 2007
Posts: 9990
    
    7

I will still recommend what I suggested in my first reply. Did you try it out?
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 917

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


My Website: [Salvin.in] Cool your mind:[Salvin.in/painting] My Sally:[Salvin.in/sally]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: GWT - Capture values of dynamically created components
 
Similar Threads
Issue with h:inputText
Creating Edit Profile Page in JSP
Pre-populating a drop down list using STRUTS
Problem with persisting text box values in JSP
hyperlink-event using a servlet