This article is to show you how to do auto-redirect to another page/taskflow on load of a page.
Using this technique, we can achieve the below also,
when an external application tries to call an adf application page using url with query parameters (visible in the url), and if we do not want those parameters to be visible explicitly in the url, then we can use this approach, where on load of a page we can capture those query parameters and we can redirect to the actual page.
when an external application tries to call an adf application page using url with query parameters (visible in the url), and if we do not want those parameters to be visible explicitly in the url, then we can use this approach, where on load of a page we can capture those query parameters and we can redirect to the actual page.
Redirect to a task-flow
To achieve our requirement, we need a page on load of which, it should redirect to a task-flow.
Redirect.jspx
Employee_task-flow
Onload of Redirect.jspx , it should redirect to Employee_task-flow. This task-flow contains a page(employee.jspx) as default activity.
Step1: Create a class OnPageLoadBackingBean which implements PagePhaseListener
Step2 : Create a backing bean scoped class for Redirect.jspx page. It should extend the OnPageLoadBackingBean class that we created in the above step and implement onPageLoad method.
Step3:Configure this bean in the pagedefinition file of Redirect.jspx
Step4:Employee.jspx contains
Save the application and run the Redirect.jspx page. It will redirect to the employee page in Employee_task-flow
So when a link in external application calls your Recirect.jspx page with query parameters and if you do not want those parameters to be visible in the URL explicitly, then onPageLoad method we can read the parameters and keep them in any scope like sessionScope..etc and redirect to another page/url.
To read query parameters, we can use the below
FacesContext fctx = FacesContext.getCurrentInstance();
ExternalContext ectx = fctx.getExternalContext();
javax.servlet.http.HttpServletRequest request = (javax.servlet.http.HttpServletRequest)ectx.getRequest();
Map requestParams = request.getParameterMap();
If the incoming url is an encoded url then we need to get the complete query string and decode it and parse it lie below
String queryString = request.getQueryString();
try{
queryString = URLDecoder.decode(queryString, "UTF-8");
//parse the query parameters here
Hashtable params = HttpUtils.parseQueryString(queryString); //deprecated
//another way to parse if you do not want to use deprecated method is by using apache's utils
//org.apache.http.client.utils.URLEncodedUtils
} catch (UnsupportedEncodingException e) {
System.out.println("UnsupportedEncodingException");
}
There are other simple ways available to get the parameter values and keep them in some scoped variables as described here https://blogs.oracle.com/shay/passing-parameters-to-an-adf-page-through-the-url-part-2 But this does not work if the incoming url is an encoded url. If the url is encoded, then we need to get the queryString part in the onPageLoad method and parse the parameters by ourselves.
To read query parameters, we can use the below
FacesContext fctx = FacesContext.getCurrentInstance();
ExternalContext ectx = fctx.getExternalContext();
javax.servlet.http.HttpServletRequest request = (javax.servlet.http.HttpServletRequest)ectx.getRequest();
Map requestParams = request.getParameterMap();
If the incoming url is an encoded url then we need to get the complete query string and decode it and parse it lie below
String queryString = request.getQueryString();
try{
queryString = URLDecoder.decode(queryString, "UTF-8");
//parse the query parameters here
Hashtable params = HttpUtils.parseQueryString(queryString); //deprecated
//another way to parse if you do not want to use deprecated method is by using apache's utils
//org.apache.http.client.utils.URLEncodedUtils
} catch (UnsupportedEncodingException e) {
System.out.println("UnsupportedEncodingException");
}
There are other simple ways available to get the parameter values and keep them in some scoped variables as described here https://blogs.oracle.com/shay/passing-parameters-to-an-adf-page-through-the-url-part-2 But this does not work if the incoming url is an encoded url. If the url is encoded, then we need to get the queryString part in the onPageLoad method and parse the parameters by ourselves.
Do you want your application to accept POST parameters (not query parameters)? Then this can be followed http://adfpractice-fedor.blogspot.com/2013/07/url-task-flow-call-with-http-post-method.html
But most of the times an external application sends parameters as query parameters.
To Redirect to a Page instead of a taskflow
we can use the below code. We should give the view activity id of a page in the viewId. The actual source of this content is from https://blogs.oracle.com/jdezveloperpm/how-to-efficiently-redirect-to-an-adf-faces-view-using-adf-controller
FacesContext fctx = FacesContext.getCurrentInstance();
ExternalContext ectx = fctx.getExternalContext();
String viewId = "employee"
ControllerContext controllerCtx = null;
controllerCtx = ControllerContext.getInstance();
String activityURL = controllerCtx.getGlobalViewActivityURL(viewId);
try{
ectx.redirect(activityURL);
}
catch (IOException e) {//Can't redirect
e.printStackTrace();
}
ExternalContext ectx = fctx.getExternalContext();
String viewId = "employee"
ControllerContext controllerCtx = null;
controllerCtx = ControllerContext.getInstance();
String activityURL = controllerCtx.getGlobalViewActivityURL(viewId);
try{
ectx.redirect(activityURL);
}
catch (IOException e) {//Can't redirect
e.printStackTrace();
}
Comments
Post a Comment