Call
Widget mainMenu = createMenu();
initWidget(mainMenu);
from the onSuccess() method of the RPC after you have set the userInfo
object.
Something like:
rpcService.getUserInfo(username, new AsyncCallback<UserInfo>() {
@Override
public void onSuccess(UserInfo result) {
UserPanel.userInfo = result;
Widget mainMenu = createMenu();
initWidget(mainMenu);
}
@Override
public void onFailure(Throwable caught) {
// Window.alert(caught.getMessage());
}
});
Remember, GWT RPC is asynchronous, so you have to always make sure you
execute dependent code blocks in sequence.
On Monday, December 12, 2016 at 4:34:22 PM UTC-5, Olar Andrei wrote:
>
> Hello,
>
> I'm creating a menu, and I basically need my UserInfo object already set
> (based on the username) before creating the menu and doing the initWidget().
> Basically I have the username, and based on this, I query the DB and get
> everything else based on that username.
> But I am using an RPC call for the backend part. How can I make sure that
> userInfo is set before proceeding to the createMenu() and initWidget() part
> ?
>
> private static UserInfo userInfo;
>
> public UserPanel() {
> container = new MaterialContainer();
> container.setFontSize("1em");
>
> setUserInfo("someUsername");
>
> Widget mainMenu = createMenu();
> initWidget(mainMenu);
> }
>
> public void setUserInfo(String username) {
> DBGetUserInfoAsync rpcService = (DBGetUserInfoAsync)
> GWT.create(DBGetUserInfo.class);
> ServiceDefTarget target = (ServiceDefTarget) rpcService;
> String moduleRelativeURL = GWT.getModuleBaseURL() + "DBGetUserInfoImpl";
> target.setServiceEntryPoint(moduleRelativeURL);
>
> rpcService.getUserInfo(username, new AsyncCallback<UserInfo>() {
>
> @Override
> public void onSuccess(UserInfo result) {
> UserPanel.userInfo = result;
> }
>
> @Override
> public void onFailure(Throwable caught) {
> // Window.alert(caught.getMessage());
> }
> });
> }
>
>
>
--
You received this message because you are subscribed to the Google Groups "GWT
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.