Skip to main content

ADF - Redirect to Another Page/task-flow on page load and can parse and hide query parameters


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.

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.
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();

   }

Comments

Popular posts from this blog

Oracle ADF - show or hide popup programmatically

Objective here is to open popup from backing bean . You can bind the af:popup like below     <af:popup id="p1" contentDelivery="immediate"               clientComponent="true"               binding="#{backingBeanScope.employee.myPopup}" > Then in java you can use the myPopup to hide and show the popup  private RichPopup myPopup ;//bound to the UI component  public void showOrHidePopup(RichPopup popup,Boolean visible){  if(visible){  RichPopup.PopupHints hints = new RichPopup.PopupHints();    myPopup.show(hints);  }  else{   myPopup.hide();  } That's all, Now you can call this method from any events like actionListener of a commandLink

Oracle ADF - Menu Skinning

Let's see how to style menu in oracle adf I assume that you have a page with menus like below The default style for the menu with alta ui theme looks like below If you want to change the look and feel of the menu, then we need to add few component level style selectors. I assume that you have a css file ready to put the custom styles that we are going to use.With the below seectors you can play around to change the look and feel /*menu hover*/ af|menu:hover{ border : 1px solid rgb(0,198,198) ; background-color: white; } /*menu hover --> menu text hover*/ af|menu:hover af|menu::bar-item-text:hover{     color: rgb(0,205,205);   } /*menu pressed*/ af|menu:depressed{ border : 1px solid rgb(0,198,198) ; background-color: rgb(0,205,205); color: White; } /*menu pressed and hover --> menu text hover, menu pressed --> menu text*/ af|menu:depressed:hover-target af|menu::bar-item-text, af|menu:depressed af|menu::bar...

Oracle Visual Builder Cloud Service- How to use switch case in action chain

Lets quickly see, how to use a switch case in action chain Consider that we are going to have a menu with items saying "Create Note", "Export Notes","More Settings". When each menu item is clicked or chosen, we need to do certain action / action chain. For this, first let's create a page and drag and drop the "Menu Button". When you drop it in the title secion you will get options to choose where you want to place the menu "startControl","endControl","Default". Let's choose it as end control to place it at the end of the title bar. In the page structure choose the "Menu" and go the "Data" tab. Add and Edit the menu items (oj-option). here we have the menu item id's ad "newNote","export","settings" When the menu is selected we need to do some action. For that we need to map an action to the menu. In the page structure choose the "Menu...

Oracle ADF - Table pagination problem from JDeveloper 11.1.1.7

Most of us would have tried to implement pagination on af:table From Jdeveloper 11.1.1.7, pagination feature is directly available for af:table with a property called "scrollPolicy". We need to have two properties in af:table scrollPolicy="page" autoHeightRows="0" Once this is set the pagination feature should be shown.But table pagination does not show up, until unless we have a floating layout around the table. When we try this, we will get a message in the log saying below falling back to scrolling mode since we need parent component to flow and authHeightRows=0 Logs looks as below This is because of the layout around the table. The table should be in a container in flow mode. For example panelGroupLayout or showDetailHeader. So the af:table should be surrounded with a panelGroupLayout When you surround table with panelGroupLayout, set the layout to "horizontal",or "vertical",or "scroll" . Because w...

Oracle ADF - button skinning / button style

How to style a commandButton in Oracle ADF Normally buttons looks like below in the alta-ui skin If you want to style your button to look like bootstap buttons (most of the morder sites use bootstrap like buttons nowadays), you can use component selectors to skin af:commandButton component. Example style classes are below /***************** Button style start **********/ af|commandButton.success{     background-color: #4dbd74;     background-image: none;     border-radius : 5px;     border : 1px solid #3ea863;     color: white;     text-shadow : none; } af|commandButton.success:hover{     background-color: #3ea863;     background-image: none;     border-radius : 5px;     border : 1px solid #3ea863;     color: white;      text-shadow : none; } af|commandButton.warning{     background-color: #ffc107;     background-im...

Oracle ADF - Simple Progress indicator or show loading image in custom typeahead / autosuggest

In the last blog Custom Autosuggest / typeahead we saw how to construct a custom typeahead / autosuggest using an input text box and a popup with select items. If the list to be filtered is smaller we wouldn't need to show a loading symbol to the user, while doing the filter process in the backing bean. But what if the the list too big to filter and the filtering process would take some time like 3 to 4 seconds. Or what if the result of search need to be fetched from an external rest end point or from an external soap service ? It would take some considerable amount of time to fetch the data. User's expect some quick response from the page, when they try to do something. So it's better to show them that the process is happening at the back end. A simple way to do that is to have loading gif image ready, and show it when the popup opens and before triggering the server event to filter the list. Once the filtered items are ready and about to be returned to the client then ...

Oracle ADF - Dialog skinning / Modern Dialog with a simple form

Lets see how to style af:dialog in oracle adf. We usually use dialog within a popup. The default dialog without any style looks like below in alta skin If you want to play with the styles of dialog to make it as a plain dialog without header and footer, you can use the component level selectors like below af|dialog{     background-color: #454d54;     border:none ; } af|dialog::header-start,af|dialog::header-end,af|dialog::header,af|dialog::footer-start,af|dialog::footer-end,af|dialog::footer{     display:none; } af|dialog::content,af|dialog::content-start,af|dialog::content-end{     border-top:none; } you can use these selectors according to your need with the above styles the dialog would look like below In addition to the css above, i have updated few things in the jspx page to make it look better with buttons aligned and form aligned to the center along with some styles for the buttons (style for buttons can be found he...

Custom Typeahead / autosuggest Search in ADF

For custom type ahead search there are many different solutions available out there. We can choose depending on what we are looking for. Let me first describe my use case. My autosuggest/typeahead search should show the filtered list of items once I entered the search text(This is the basic requirement, that can be achieved easily with the readily available autosuggest in ADF). When I select one item from the list, I should be able to get the selected item along with all additional information like id,name,date etc, instead of getting only id or name. The normal autosuggest solution given by Frank Nimphius available here http://www.oracle.com/technetwork/developer-tools/jdev/autosuggest-090094.html This one can do the basic autosuggest which can give the selected item's id and label. But what If you need to have access to addition information, while selecting one of the item from the list, like city ,country,department..etc. So I have customized the solution provided by Fr...

Oracle Visual Builder Cloud Service - Take photo action

Let's see how to use Take photo action in an action chain.It's a mobile application, and let's assume that you want to take photo, while clicking on a button. We are going to use "Take Photo" action for this. I have a page with a button called "Take Photo" in it. Lets add an event for this button click. When you create an event an action chain is created. Go to the action chain, and drag and drop the "Take Photo" action You can change the source for the "Take Photo" action. It has options as "Camera","photoLibrary","savedPhotoAlbum". Let's go with "camera" option. Explore the other options and change as you need. This action returns the file path of the captured photo. You are free to play around with that file path. You can use it to show the captured image, or use it to process the image. We are going to use the filepath and show the image For that let us create ...

How to enable ADF Faces Extension for css editor in JDeveloper

This article is to show you how to enable adf faces extensions for css editor in jdeveloper 11.1.1.9 You have an ADF Fusion Application and you have created a css file to write custom skin css properties. You are typing the adf faces components to customize their look and feel like af|panelFormLayout But the editor is not showing up the typeaheads? I mean the css editor is not helping you by listing out the options while you type af| ? Then check whether ADF extensions are enabled or not and if not enable it. how to do it ? Go to Tools --> Preferences --> CSS Editor And enable the ADF Faces Extension checkbox Click Ok Now go back to the css file. In the editor, now it will help you with adf extensions.