views:

53

answers:

4

I'm new to GWT and trying to make a simple app (like a small version of fmylife). Up to now i made a composite that loads the facts and another composite that has a form to submit new facts (this one has a load method that clear the list and populate again).

I have a button that when you press it, it shows a Window with a form. That form is used to add new Facts. But I want to refresh the main page when the Fact is added correctly and close this window.

How should I do this? Should I pass some kind of callback to the Window form?

Edit: I didn't express well enough, Window is a DialogBox provided by smartGWT.

A: 

You should use DialogBox or PopupPanel instead of opening a new window (most modern browsers opt to open a new tab either way). That way you won't leave the page (that's the whole point of this AJAX thing, right?), you'll just overlay a new Widget over it and then on "submit" it will hide/destroy itself and add a new fact (without reloading the whole page).

Igor Klimer
A: 

Agreed with the DialogBox and PopupPanel solution above. However, if you'd still like to use Window, the following solution comes to mind.

Extend Window and provide hooks to the values you want back. Then, when you create the new CustomWindow, call the addWindowCloseHandler method to get notified when the CusomWindow is being closed. On that event, get the values you need and allow the window to close. Then make an async call to refresh your main page.

Arthur Kalmenson
+3  A: 

Sure, why not? Pass a callback with some method like onSave to the composite contained in the DialogBox. Design the flow in such a way that the DialogBox composite is always editing the fact model, and it it not be aware of whether it is creating a new fact model or editing an existing one. Let the DialogBox invoke onSave using the callback, when the user submits the popup.

Keep the fact collection data structure CRUD logic out of the DialogBox composite.

Ashwin Prabhu
+2  A: 

Take a look at Events and the Event Bus.

You can also watch this video for a better explanation.

Macarse