Oracle JDeveloper and Oracle ADF Blog

  • October 30, 2010

How-to efficiently redirect to an ADF Faces view using ADF Controller

Frank Nimphius
Master Principal Product Manager
ADF Faces developers use facesContex.getExternalContext().redirect(String) to issue a GET request to a JSF view. Using ADFc, the redirect URL should neither be read from the current UIView root directly or provided in the form /faces/<viewId name>. Instead, have the controller generating the redirect String for a specific viewId as shown below:

FacesContext fctx = FacesContext.getCurrentInstance();
ExternalContext ectx = fctx.getExternalContext();
String viewId = "... add viewId...."
ControllerContext controllerCtx = null;
controllerCtx = ControllerContext.getInstance();
String activityURL = controllerCtx.getGlobalViewActivityURL(viewId);try{
ectx.redirect(activityURL);} catch (IOException e) {//Can't redirect
Why ? Because a redirect is a Get request and you don't want ADFc to treat it as a new application request but instead retrieve the internal controller state. For this you need the state toke in the redirect URL, which is what the code line above does

Join the discussion

Comments ( 4 )
  • guest Monday, August 13, 2012

    Very nice! It works correctly for me.

  • NTG Thursday, October 1, 2015

    I am using above code for redirect. But when I press back button of browser I get this -


    Error 403--Forbidden

    From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1:

    10.4.4 403 Forbidden


    How can I fix it?

  • Frank Nimphius Monday, October 5, 2015

    The problem seems to be that you are not browsing back to a URL bt to a JSF action (JSF uses postback actions, which means it calls itself to perform - in this case - a redirect). So the fix would be to either 1) delete the browser histiry using JavaScrit (so the bak button doesn't do a thing), 2) provide a back button in your application so the browsre back button is not used 3) attempt to handle the browse back use case in a life cycle listener to then do the right thing.

  • guest Sunday, January 15, 2017

    Thanks your code helped a lot

Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.