So my question is the following :
Say, I am displaying data in in a flextable after getting it from a database, am doing this in a routine manner using loops.
Now, in the entire First Column, the text should be clickable, i.e. I should be able to add a Click Handler to First Column values (as I gotta load another table upon clicking any of the first column text vals.)
Question : How can I generate such Hyperlink tags while in a loop ? The problem comes when I try to do so as I don’t know how to name them as the loop runs and use the same concept while adding ClickHandlers.
Should I use something else other than Hyperlink for this task. Kindly explain how ?
I really appreciate help in this as I am a very new GWT coder.
— Chirayu
Using a Hyperlink is maybe not the best way to do something like this, because you shouldn’t use a ClickHandler with a Hyperlink. A Hyperlink sets a HistoryToken and you should respond to the change of the History.
I would use a Label and maybe style it as a normal link if you want to have the same look and feel.
(I will use a Label in the following example but you could change it to a Hyperlink if you want to.)
I would create a class that extends Label. This class would have an ID you set in the constructor. You would send this Id to the server to get the new FlexTable. In the constructor you add a ClickHandler that reads the id field and sends it to the server to get the new FlexTable.
In your loop you would just create objects of the new class and give it the appropriate parameters(I assume you have an ArrayList with the result. The Objects in this ArrayList would have text and id):
I hope this gives you at least something to start, if something is still unclear leave a comment and I will try to help make things clear.
Edit based on Chirayu’s post:
It’s hard to explain something like this without knowing your application.
I normally implement the Singleton Pattern to get a specific widget.
So I would create a class like this:
In your EntryPointClass you would have something like this:
You can now call the YourPanel.getInstance() method in the onSuccess() part of your service to change the content of the panel:
I hope that helps. Leave a comment if it doesn’t.
Sample app
Sample app running
Sample app source code