gwtgwt-history

Adding History in GWT program


I am writing History.newItem("step2") but even after executing this instruction the method it should call is public void onValueChange(ValueChangeEvent event) { //code }

but when I am doing so the method is not called I dont understand why it is not calling the method.

Below is the entire code.

{
package org.adrianwalker.gwt.uploadprogress.client;

import com.google.gwt.user.client.History;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import org.adrianwalker.gwt.uploadprogress.client.view.UploadProgressView;

public final class UploadProgress implements EntryPoint, ValueChangeHandler {

  private static final UploadProgressView UPLOAD_PROGRESS_VIEW = new UploadProgressView();
    Label step_co=new Label("Step1");
  @Override
  public void onModuleLoad() {
    Button next1=new Button("Next");

    AbsolutePanel master_panel=new AbsolutePanel();
    //RootPanel rootPanel = RootPanel.get("content");
      master_panel.setStyleName("master_panel");
      master_panel.setHeight("100px");
      master_panel.setWidth("300px");


    master_panel.add(step_co,100,25);
    RootPanel.get("master").add(master_panel,100,25);
    RootPanel.get("content").add(UPLOAD_PROGRESS_VIEW,100,150);
    RootPanel.get("content").add(next1);

      next1.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                History.newItem("step2",true);

               RootPanel.get().add(new Label(History.getToken()));
//                changeStep("token");
          }});

    RootPanel.get("content").add(next1,150,550);

  }



   public void onValueChange(ValueChangeEvent event)
 {
RootPanel.get().add(new Label("In value change"));
 String token=History.getToken();
 changeStep(token);
 }
   public void changeStep(String token)
    {
       if(token.equals("step2"))
       {
           step_co.setText("Step2");
           RootPanel.get("content").clear();
        }
   }


}
}

Please tell me how could make this call the method public void onValueChange(ValueChangeEvent event) in the History.newItem(("step2") instruction.


Solution

  • You will have to call

    History.addValueChangeHandler(this)
    

    somewhere in your code. That is how the history object knows to call your method when it's fired.

    Check out GWT's documentation for some example code.