2010-07-15 44 views
2

参数这里是我的历史价值变动事件处理程序:GWT - 在片段

public void onValueChange(ValueChangeEvent<String> event) { 
    String token = event.getValue(); 

    if (token != null) { 

     if (token.equals("!list")) { 
      GWT.runAsync(new RunAsyncCallback() { 

      public void onFailure(Throwable caught) { 
      } 

      public void onSuccess() { 
       presenter = new ContactsPresenter(rpcService, eventBus, new ContactsView()); 
       presenter.go(container); 
      } 
     }); 
     } 
     else if (token.equals("!add")) { 
      GWT.runAsync(new RunAsyncCallback() { 

      public void onFailure(Throwable caught) { 
      } 

      public void onSuccess() { 
       presenter = new EditContactPresenter(rpcService, eventBus, new EditContactView()); 
       presenter.go(container); 
      } 
     }); 
     } 
     else if (token.equals("!edit")) { 
      GWT.runAsync(new RunAsyncCallback() { 

       public void onFailure(Throwable caught) { 
       } 

       public void onSuccess() { 
        presenter = new EditContactPresenter(rpcService, eventBus, new EditContactView()); 
        presenter.go(container); 
       } 
      }); 
     } 

    } 

正如你所看到的,要www.domain.com/#edit负载高达编辑视图。但是,我将如何在片段中指定一个参数,例如一个ID,并将其传递给Edit Contacts Presenter?

所有的

www.domain.com/#edit/1

回答

1

您通过event.getValue()获得的令牌只是一个字符串 - 因此您可以使用token.split("/")获取所有片段,然后根据例如第一个片段进行操作(如果我们得到“编辑”,那么我们应该期待下一个号码等)。

+0

是的,比我想象的要简单得多!谢谢! – 2010-07-15 16:29:55

1

首先,你的例子看起来破碎的添加和编辑的情况下做同样的事情的onSuccess。但我敢肯定你已经知道;-)

我没有因为1.5使用GWT,但是从内存中我们做了与字符串匹配,如:

if (token.startsWith("edit")) { 
    String userID = token.substring("edit".length() + 1); 
    //... 
} 

我倒是希望有在较新版本的GWT中使用助手来序列化和反序列化对象模型的各个位以支持历史记录的URL安全令牌是更加痛苦的GWTisms之一。

+0

看起来不像是这样,所以我只是用基本的String方法做了。 =) – 2010-07-15 16:30:28