我有两个演示者:DevicePresenter和ContainerPresenter。我在DevicePresenter中放置一个PlaceRequest,用这样的参数调用ContainerPresenter:
PlaceRequest request = new PlaceRequest.Builder()
.nameToken("containersPage")
.with("action","editContainer")
.with("containerEditId", selectedContainerDto.getUuid().toString())
.build();
placeManager.revealPlace(request);
在我的ContainersPresenter中,我有这个被覆盖的方法:
@Override
public void prepareFromRequest(PlaceRequest placeRequest) {
Log.debug("prepareFromRequest in ContainersPresenter");
super.prepareFromRequest(placeRequest);
String actionString = placeRequest.getParameter("action", "");
String id;
//TODO: Should we change that to really retrieve the object from the server? Or should we introduce a model that keeps all values and inject that into all presenters?
if (actionString.equals("editContainer")) {
try {
id = placeRequest.getParameter("id", null);
for(ContainerDto cont : containerList) {
Log.debug("Compare " + id + " with " + cont.getUuid());
if(id.equals(cont.getUuid())) {
containerDialog.setCurrentContainerDTO(new ContainerDto());
addToPopupSlot(containerDialog);
break;
}
}
} catch (NumberFormatException e) {
Log.debug("id cannot be retrieved from URL");
}
}
}
但是当调用revealPlace时,浏览器中的URL保持不变,而是显示默认的演示者(Home)。 当我打印请求时,似乎没问题:
PlaceRequest(nameToken=containersPage, params={action=editContainer, containerEditId=8fa5f730-fe0f-11e3-a3ac-0800200c9a66})
我的NameTokens是这样的:
public class NameTokens {
public static final String homePage = "!homePage";
public static final String containersPage = "!containersPage";
public static final String devicesPage = "!devicesPage";
public static String getHomePage() {
return homePage;
}
public static String getDevicesPage() {
return devicesPage;
}
public static String getContainersPage() {
return containersPage;
}
}
我错过了什么?谢谢!
答案 0 :(得分:1)
在您的原始代码中,在构建PlaceRequest时,您忘记了'!'在你的名字开头。
.nameToken("containersPage")
,而您的NameTokens条目是
public static final String containersPage = "!containersPage";
正如您所指出的,在NameTokens中引用常量不太容易出现如此容易出错的错误!
答案 1 :(得分:0)
有时问题存在于“耳朵之间”。如果我避免字符串,但使用NameTokens中的正确符号,如
PlaceRequest request = new PlaceRequest.Builder()
.nameToken(NameTokens.containersPage)
.with("action","editContainer")
.with("containerEditId", selectedContainerDto.getUuid().toString())
.build();
它运作得很好。遗憾!