开发者

Calling a Composite's GWT method from another Composite

开发者 https://www.devze.com 2023-01-08 12:05 出处:网络
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

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 开发者_JAVA百科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.


Take a look at Events and the Event Bus.

You can also watch this video for a better explanation.


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.


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).


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消