I have a jsf page. I want to reload the page everytime an it is refreshed
I tried this code but it was not working
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 "";
}
So I decided to use numbers to indicate whether it has been loaded.
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";
}
This is my jsf page
<f:metadata>
<f:viewParam name="foo" value="#{bean.foo}" />
<f:viewAction action="#{buildsheetController.onload}" />
</f:metadata>
I got this error
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.
Update: When I set the second return value to null, it gives me this error
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.
I found out the problem to my codes. My second return is not supposed to be an empty statement or irrelevant strings. In order to return values for the first "if" statement but not the "else" statement, I moved the return part to a whole new method. I also remove the return statement from the onLoad method.