下面是我的历史值更改事件处理程序:
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
发布于 2010-07-15 23:00:24
你通过event.getValue()得到的令牌只是一个字符串--所以你可以使用token.split("/")来获得所有的片段,然后根据第一个片段继续,例如,如果我们得到“编辑”,那么接下来我们应该期待一个数字,依此类推。
发布于 2010-07-15 21:00:21
首先,您的示例看起来失败了,因为添加和编辑用例执行的是完全相同的onSuccess操作。但我相信你已经知道了;-)
我从1.5开始就没有使用过GWT,但在内存中我们使用了字符串匹配,例如:
if (token.startsWith("edit")) {
String userID = token.substring("edit".length() + 1);
//...
}我希望在较新版本的GWT中有帮助器,因为将对象模型的一小部分序列化和反序列化到URL安全令牌以支持历史是比较痛苦的GWTisms之一。
https://stackoverflow.com/questions/3255353
复制相似问题