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.
public class FlexTableLabel extends Label implements ClickHandler {
int id=0;
public FlexTableLabel(String text, int id) {
this.id=id;
this.setText=text;
this.addCickHandler(this);
}
public void onClick(ClickEvent event) {
//sends the id to the server, of course you need to replace it with your
//service
yourService.getNewFlexTable(this.id);
}
}
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):
for(int i=0; i<result.size;i++) {
FlexTable.setWidget(i,0, new FlexTableLabel(result.get(i).text, result.get(i).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:
public static YourPanel extends Panel {
private static YourPanel instance=null;
public static YourPanel getInstance() {
if(instance==null) {
instance=new YourPanel();
}
return instance;
}
}
In your EntryPointClass you would have something like this:
public class YourEntryClass extends EntryPoint {
public void onModuleLoad() {
RootPanel.get().add(YourPanel.getInstance());
}
}
You can now call the YourPanel.getInstance() method in the onSuccess() part of your service to change the content of the panel:
yourService.getNewFlexTable(this.id, new AsyncCallback<ArrayList<String>>() {
public void onSuccess(ArrayList<String> result) {
For(int i=0;i<result.size;i++) {
YourPanel.getInstance().add(result.get(i);
}
}
});
I hope that helps. Leave a comment if it doesn't.
Sample app
Sample app running
Sample app source code