0

I have a page called newTest.xhtml, backed by A CDI Bean called NewTest, When the user clicks a button it should do some work in the backinhg bean and return to the same page newTest.xhtml. The problem is that When I click the button the browser does not refresh the page. when I click refresh manually then the browser refresh the page. My Question is : In JSF how Can I tell the browser to ALWAYS Load the page from the server not the cache

public String doWork() {
        //do some work

        return "/newTest.xhtml?faces-redirect=true";
    }

Fixed I have fixed The problem by using ajax's render="@all"

<h:commandButton  >
    <f:ajax execute="@all" render="@all"/>
</h:commandButton>
usertest
  • 2,140
  • 4
  • 32
  • 51
  • 1
    So effectively your question is how to not cache a page. Lots of questions and answers about that in stackoverflow – Kukeltje Apr 14 '17 at 18:24
  • No. that's not my question. my question is more specific than that. and it's NOT a duplicate @BalusC of that question – usertest Apr 15 '17 at 17:10
  • Several things: 1) The way the question was posted it IS a duplicate, 2) StackOverflow works by creating **answers**, not editing questions and put the solution in there. 3) Questions and answers have a relation. Your question, nor answer have in no way any indication on how they are related. 4) execute="@all", render="@all" is a strange not very common and in some ways error prone solution. You most likely can update smaller parts of the page 5) Wondering why you did a redirect at all if you wanted to stay on the same page 6)... – Kukeltje Apr 16 '17 at 10:23
  • 1) I cannot create an answer thanks to BalusC who mark it as duplicate. 2) you have not suggest an answer to fix the problem so if the fix I found is error prone, for now, it's the only answer I know. 3) The page is minimal so render"@all" is OKay, as I want all fields to be updated with new values the backing bean made. – usertest Apr 16 '17 at 16:08

1 Answers1

0

You can make redirection to the request page

ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
externalContext.redirect(((HttpServletRequest) externalContext.getRequest()).getRequestURI());
michal
  • 1,796
  • 1
  • 13
  • 11