Search code examples
gwtsmartgwt

How to redirect to another page in GWT application


  • I have a client class UserLogin which also represents my entrypoint . I ask for a password and login to the user, I make my server side check and I get a response in the form of a string representing an xml file that I must parse and generate the widget with the coded information this xml .
  • I'm stuck here: if the user is recognized , I want to redirect to a second page "home" which will present the user with the component provides the answer. Only I do not know how to do that normally in class that generates the home I have to have the onModuleLoad () method that will parse the response from the server and display the desired elements.

Solution

  • GWT is Single Page Web Application,to Navigating one Screen to other screen just clear layout Container and add the newly created Container to RootPanel.See example code,

    HorizontalPanel hp=new HorizontalPanel();
    Button btn=new Button("Login");
    hp.add(new TextBox());
    hp.add(new PasswordTextBox());
    hp.add(btn);
    RootPanel.get().add(hp);
    
    btn.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent clickEvent) {
    RootPanel.get().clear();
    RootPanel.get().add(new screen());
    }
    });