Tuesday May 10, 2011

How-to efficiently redirect an ADF Faces view using ADFc

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

About

The Oracle JDeveloper forum ranks in the Top 5 of the most active forums on the Oracle Technology Network (OTN).



The OTN Harvest blog is a summary of selected topics posted on the OTN Oracle JDeveloper forum.



It is an effort to turn knowledge exchange into an interesting read for developers who enjoy little nuggets of wisdom





Frank Nimphius

Search

Archives
« April 2014
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
   
       
Today