Wednesday, June 16, 2010

Working with Dynamic Regions in Oracle ADF

Hi all,

I will extend my old post "Creating Pages with Regions in Oracle ADF" here so now i will show you how to work with Dynamic Region.

Note: Updated on 23-Sep-2010 Identified bug in the sample code. Thanks Asim and Pino

What is Dynamic Region? 

According to Oracle docs:
An ADF dynamic region is an ADF region where the task flow binding dynamically
determines the value of its taskFlowId attribute at runtime. This allows the Fusion
web application to determine which bounded task flow to execute within the ADF
dynamic region based on the result of evaluation of the task flow binding’s
taskFlowId attribute.

In this example:
- We will have 2 Bounded task flow one will show the list view of the Employee table and other shows the form style view
- We will have a home page with 2 different button to activate the particular region.

As shown the runtime view of the use case.




Steps to follow: 
(I assumed you already have enough ADF experience now if not feel free to check ADF section on this blog)

1) Create 2 bounded task flows with page fragments, named list-flow and form-flow respectively.
2) Create view activities on these pages one each.
3) Drag and drop the collection from data control and design your page as your taste.
4) Create a new activity in adfc-config flow called Home
5) Create home page by choosing default 2 column template as shown in the slide


6) Create 2 button on the first facet labeled as List and Form respectively.
7) Drag a List-flow to second facet and choose Dynamic Region from the menu
8) Create a Managed Bean named "DynamicRegionBean" class "DynamicRegion" Press OK Scope must be viewScope
9) We are not passing parameters to our Task flow so we will keep this default press OK
10) Change the code in the DynamicRegion class as following the method getDynamicTaskFlowId()  returns the TaskflowId of the BTF so we have changed our code to return the ID dynamically


11) Drag and drop af:setPropertyListener to both buttons on HOME page set values to static string as 'list' and 'form' respectively as shown in the slide

12) Set the partial submit to true on both these buttons and set partial triggers property to button ids in af:region component.

Thats all you are ready Run the page Press Form button the form-flow will appear press List button the other view appears




More Reading: Oracle Fusion Developer Guide Working with Dynamic Regions

Download the example workspace


Note: This example is to show how to Dynamic Regions works, When you have more than couple Regions then its better to write the Region code logic in a separate java class for ease of maintenance and import that class in DynamicRegionBean class.


Have a nice day,
Baig

26 comments:

  1. Hi
    Very nice tutorial. But in employee form navigation button do not rendered next or previous record. Any idea how to resolve this issue.

    ReplyDelete
  2. Hi,

    I implemented your example, but instead of buttons on the parent jsp, I'd like to use something like a link, golink..etc.

    When I try using your example with one of those components, I receive errors.

    Also, I noticed that there is a type called 'regionNavigation' when you are creating a SetPropertyListener. I'm curious about that, and cannot find documentation...

    Do you have a suggestion for what I am asking for?

    Thanks,

    Joel

    ReplyDelete
  3. Hi Joel,

    What error you are receiving? The purpose of setPropertyListener is just to assign a value to backing bean.

    ReplyDelete
  4. Asim i have updated this Post. in previous sample code i wrongly set the backing bean scope to BackingBean which should be ViewScope.

    ReplyDelete
  5. Hi,

    I used some page fragments as DynamicRegion but cannot set the backing bean from
    8) Create a Managed Bean named "DynamicRegionBean" class "DynamicRegion" Press OK Scope must be viewScope

    to view only to backingBean.
    And I have read that for page fragments only backingBean is used.

    For the view Scope the application remained suspended without any error...and witth backingBean is working.

    Have any ideea?

    Thanks,
    H

    ReplyDelete
  6. Hi,
    I have an app that has two page fragments flows (jsff)
    I have the problem that for the 8) step:
    8) Create a Managed Bean named "DynamicRegionBean" class "DynamicRegion" Press OK Scope must be viewScope

    when i put the backingBean as bean scope it's working but it's not working for the view scope.
    My application remained stuck without any error.

    I have read that only backingBeans scope is used with page fragments but i think the view scope will solve my problem (cannot remain in the same flow...it go to the default one!!!)

    Do you have any ideea..plz?

    Thanks,
    H

    ReplyDelete
  7. Hi,

    set the scope of the bean in task flow managed bean section.

    The Bean should be in viewscope bean because you are maintaining the stage of the current fragment. If you use the backingbean scope your bean attributes will reinitialize and will not give the desired results.

    Hope it helps

    ReplyDelete
  8. I have succeded in the end.
    Thanks for the hint....
    I havent set from the begining the viewScope correctly but after a closer look over your app I have make it working.

    Regards,
    Horatiu

    ReplyDelete
  9. Hi,

    I have a similar app. where all the taskflows are working fine... except search taskflows. based on the input appropriate taskflow will get invoked but it will stuck in between. It will not allow to fetch the results.

    Please help

    ReplyDelete
  10. Hi Shiv,

    I am not sure what could be issue. If you can share the code with me then i can help

    ZB

    ReplyDelete
  11. i defined a dynamic region. dynamic region updates on clicking navigation link in

    navigation facet. Suppose If i click on navigation link A and it calls task flow A and it

    goes to deafult activity but if i moved from default activity to next link. And IF I again

    click navigation link A it doesnt invoke task flow A . I need click on other navigation

    link then only If i click back on navigation link A then it call. How can i move back to my default activity of task flow A.

    ReplyDelete
  12. Hi Baig,
    I have a similar use case but suppose if i modify something in one taskflow when i return second time to the same task flow i need to reset the task flow..any suggestions?

    For example:
    I the above example if i modify employee name in form view and without saving navigate to list view and then again come back to form view.
    Now I want the form view to be reset to original state rather than showing me the modified name which i modified earlier and did not save.

    ReplyDelete
  13. Hi Rohit and Rajesh,

    Your use cases looks similar its kinda tricky i have to try this.

    Thanks,
    ZB

    ReplyDelete
  14. dear Mr.baig ,
    good day ,
    how are you , i hope you are fine .
    i watched most of your video about oracle adf , i find it very usefull , god bless you .
    i want to ask how to create dynamic menu driven from database , wether to user menu item or tree or accordian panel .
    thank you .

    ReplyDelete
  15. Hi baig,
    Good day,
    Hope you are doing great.
    I working on Online test module, i am new to ADF
    here i am unable to create radio buttons in ADF, how to link with database values dynamically to radio button. can you plz help me

    Regards,
    Suresh

    ReplyDelete
  16. Hi Suresh,

    Please try this page http://docs.oracle.com/cd/E24382_01/web.1112/e16182/lists.htm#BEIBAFDD

    ZB

    ReplyDelete
  17. Hi Zeeshan,

    Is is possible to drag the contents of the dynamically rendered region (say employee table) to the Main tree node (say to a different department)?

    Thanks

    ReplyDelete
  18. Hi sachin,

    Yes it is possible check the following link

    http://www.baigzeeshan.com/2011/01/drag-and-drop-collection-in-oracle-adf.html

    https://blogs.oracle.com/adf/entry/insert_record_by_drag_drop_from_adf_tree_to_adf_tree_table

    you can have your custom logic to change department. I remember reading some blog post on same topic.

    ZB

    ReplyDelete
  19. Hi Zeeshan,

    Could you tell me how to add button to an existing Dynamic ADF region?

    Thanks,
    Utkarsha

    ReplyDelete
    Replies
    1. Hi,

      Can you provide more information on the requirement. Do you want to dynamically create a button ?

      Regions in ADF are simple Task flows you can add button simply on design time and redeploy application. If you are using ADF Library Jars you can deploy them as shared library in Weblogic. In that case you can only change and deploy your ADF library jar to WLS it will automatically pick up changes on runtime.

      Hope that answer your question.

      Zeeshan

      Delete
  20. Hey Zeeshan,
    Thanks for the nice tutorial.
    Here I have slight different requirement. I want to load second task-flow on click of one button, but that button is present inside the the 1st task flow (the button inside jsff).

    Can you plz help me with that what can I use for this case?

    ReplyDelete
    Replies
    1. Hi,

      The steps are same if you want to call taskflow within taskflow

      Regards,
      Zeeshan

      Delete
    2. Hi Zeeshan, I tried to use a selectOneChoice and based one selection.the dynamic region should show different TF's. I have configured a valueChangeListner for selectOneChoice, however it is not getting fired.I have used viewScope for my managed bean.

      Can u pls help me on this?

      Delete
    3. Hi Jins,

      Please paste your code I will take a look.

      Zeeshan

      Delete