我有两个演示器:DevicePresenter和ContainerPresenter。我在DevicePresenter中放置了一个placerrequest来调用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;
}
}
我错过了什么?谢谢! 在您的原始代码中,当构造PlaceRequest时,您忘记了'!在您的铭牌的开头。
.nameToken("containersPage")
而您的NameTokens条目是
public static final String containersPage = "!containersPage";
正如您所指出的,在NameTokens中引用常量不太容易犯这样的错误!
有时问题存在于"耳朵之间"。如果我避免字符串,但使用NameTokens中的适当符号,如
PlaceRequest request = new PlaceRequest.Builder()
.nameToken(NameTokens.containersPage)
.with("action","editContainer")
.with("containerEditId", selectedContainerDto.getUuid().toString())
.build();
效果很好。对不起!