tags:

views:

914

answers:

2

Hello,

I seem to be suffering from some fundamental misunderstanding of the way that GWT async calls work and/or how widgets are updated upon receipt of a callback.

I've created the two interfaces as well as the implementation and they seem to be communicating with one another. I make this claim based on reasonable looking data observed while stepping through with the eclipse debugger: the result variable in the onSuccess method below contains what I expect it to and the grid that I am attempting to populate ends up being filled with the data from results upon exit from the loop. However when the onSuccess call returns, no grid is displayed in my GUI as per the uhpScrollPanel.setWidget(uhpGrid) call, and no exceptions of any sort are thrown.

I must be be overlooking something obvious, has anyone got any ideas about where to look?

 final ScrollPanel uhpScrollPanel = new ScrollPanel();
 uhpVert.add(uhpScrollPanel);
 uhpScrollPanel.setSize("100%", "100%");


 //build and populate grid
 UpdateHistoryServiceAsync uhpService = UpdateHistoryService.Util.getInstance();

 uhpService.getUpdateHistory(new AsyncCallback<List<UpdateHistoryEntryBean>>() {

  public void onFailure(Throwable caught) {
   System.out.println("OnFailure");
   caught.printStackTrace();

   final Label uhpErrorLabel = new Label("Server Unable to Grab History...");
   uhpScrollPanel.setWidget(uhpErrorLabel);
   uhpErrorLabel.setSize("100%", "100%");

  }

  public void onSuccess(List<UpdateHistoryEntryBean> result) {
   int length = result.size();

   final Grid uhpGrid = new Grid();
   uhpScrollPanel.setWidget(uhpGrid);
   uhpGrid.setBorderWidth(1);
   uhpGrid.setSize("100%", "100%");
   uhpGrid.resize(length, 3);

   int i = 0;
   for (UpdateHistoryEntryBean entry : result) {
    uhpGrid.setText(i, 0, String.valueOf(entry.getSourceId()));
    uhpGrid.setText(i, 1, entry.getTitle());
    uhpGrid.setText(i, 2, entry.getBody());
    i++;
   }
  }

 });
A: 

Your onSuccess() method is not defined correctly, as a parameter it receives an Object, and you must downcast it afterwards.

Meaning, the signature should be:

public void onSuccess(Object result)

After that, you can explicitly downcast the object you know you got back like so:

List<UpdateHistoryEntryBean> resultList = (List<UpdateHistoryEntryBean>) result;
Yuval A
Yuval, are you certain? I'm using GWT 1.5 and Java 1.5 - full support for generics. That method sig was generated via tool support (GWTDesigner to be specific...). In any event the expected data is turning up in my result variable so I think that is not the issue. Thanks for trying though!
sweeney
in GWT 1.5+ you can do this, so it's not wrong
rustyshelf
Sorry, I'm used to working with GWT 1.4 :)
Yuval A
Not the answer in this case but still a useful sanity check for anyone using GWT 1.4 but mistakenly compiling with 1.5 rules via some tool.
sweeney
A: 

Well it turns out that the quick fix is to add the grid to a VerticalPanel rather than a ScrollPanel. The question now becomes - why should that matter, and how do we get around this dilemma?

sweeney
I think you need to post that as a seperate question, as it no longer has anything to do with your question title
rustyshelf