-2

我有一个 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.
4

1 回答 1

-1

我发现了我的代码的问题。我的第二次返回不应该是空语句或不相关的字符串。为了返回第一个“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

}
于 2018-07-31T08:43:05.600 回答