Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically do JSF internal page forward?

Tags:

jsf

jsf-2

forward

How to do JSF internal page forward programatically in managed bean, on some condition (like whenever an exception occurs)? I do not want to change the URL while forwarding to other page.

Right now I redirect to another page programmatically using this, but this changes the URL.

FacesContext.getCurrentInstance().getExternalContext().redirect();
like image 866
Rajat Gupta Avatar asked Apr 23 '14 19:04

Rajat Gupta


2 Answers

Try this:

public void forward(){
    String uri = "destination.xhtml";
    FacesContext.getCurrentInstance().getExternalContext().dispatch(uri);
}
like image 110
Mr.J4mes Avatar answered Dec 06 '22 00:12

Mr.J4mes


You can do using

   FacesContext.getCurrentInstance().getViewRoot().setViewId("your target view id");
   FacesContext.getCurrentInstance().renderResponse();   

or you can use

   FacesContext.getCurrentInstance().responseComplete();  

Hope this helps.

like image 42
Srikanth Ganji Avatar answered Dec 05 '22 23:12

Srikanth Ganji