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

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
     e.printStackTrace();
   }
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
Comments:

Very nice! It works correctly for me.

Posted by guest on August 13, 2012 at 08:51 PM BST #

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?

Posted by NTG on October 01, 2015 at 08:14 PM BST #

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.

Posted by Frank Nimphius on October 05, 2015 at 08:44 AM BST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

logo
A blog maintained by the JDeveloper product management team. We'll use it to post announcements, occasional how-to's and any other relevant information around JDeveloper and ADF.

See other PM Blogs

Shay, Frank, Grant, Duncan, Chris, Steve ,Joe, Dana, Many more in our blog feed
Follow JDeveloper on Twitter and Facebook

Search

Categories
Archives
« May 2016
SunMonTueWedThuFriSat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
    
       
Today