我有一个jsf页面。我想在每次刷新时重新加载页面
我试过这个代码,但它不起作用
public String onload() {
UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
String id = viewRoot.getViewId();
if(previousPage!=null && previousPage.equals(id)){
return "brcmBuildSheet?faces-redirect=true";
}
previousPage = id;
return "";
}
所以我决定用数字来表示它是否已加载。
public String onload() {
if (previousViewID !=nextViewID ){
nextViewID=0;
System.out.println("reload");
return "brcmBuildSheet?faces-redirect=true"; //brcmBuildSheet?faces-redirect=true
}
++nextViewID;
System.out.println("first page");
return "First page, but increment value for reload";
}
这是我的jsf页面
<f:metadata>
<f:viewParam name="foo" value="#{bean.foo}" />
<f:viewAction action="#{buildsheetController.onload}" />
</f:metadata>
我收到这个错误
JSF1095: The response was already committed by the time we tried to set the outgoing cookie for the flash. Any values stored to the flash will not be available on the next request.
更新:当我将第二个返回值设置为null时,它会给我这个错误
2018-07-30T14:57:52.975+0800|Severe: JSF1094: Could not decode flash data from incoming cookie value Invalid characters in decrypted value. Processing will continue, but the flash is unavailable for this request.
我发现了代码的问题。我的第二个返回不应该是一个空语句或不相关的字符串。为了返回第一个"if"语句而不是"else"语句的值,我将返回部分移到了一个全新的方法中。我还从onLoad方法中删除了return语句。
public void onload() {
if (reload) {
System.out.println("reload");
reload = false;
refresh();
}
else {
System.out.println("first page");
buildsheetList = getBuildsheetService().getAllBuildsheet();
batch = null;
title = null;
misc = null;
}
}
public String refresh() {
return "brcmBuildSheet?faces-redirect=true"; // brcmBuildSheet?faces-redirect=true
}