Database Driven ADF Tree Menu
Database Driven ADF Tree Menu
Creating Menu Table 1. Create Menu table with hierarchical structure. Take a note of the self-referencing foreign key. CREATE TABLE ADF_MENU (MENU_ID NUMBER(5), DESCRIPTION VARCHAR2(60), DEFINITION VARCHAR2(200), PARENT_MENU_ID NUMBER(5), MENU_TYPE VARCHAR2(1), DISPLAY_SEQ NUMBER(3), CONSTRAINT GEN_MENU_PK PRIMARY KEY (MENU_ID) ENABLE, CONSTRAINT GEN_MENU_FK1 FOREIGN KEY (PARENT_MENU_ID) REFERENCES GEN_MENU (MENU_ID) ENABLE );
Comments Primary key The label that will be displayed on the tree. This will hold taskFlowIds like for example "/WEBINF/flows/tf_employee.xml/tf_employee". PARENT_MENU_ID The id of the containing menu. This table is recursive. MENU_TYPE This field will enable us to show different icons per type. This is also used to render the menu as outputText or commandLink. DISPLAY_SEQ The sorting or display sequence of the menus. Sample Data
MENU _ID 1 2 3 4 DESCRIP TION General General Ledger Inventory Supply Chain Employee s Departme nts DEFINITION PARENT_ME NU_ID MENU_T YPE 1 1 1 1 /WEBINF/flows/tf_employee.xml#tf_ employee /WEBINF/flows/tf_department.xml#tf _department /WEBINF/flows/tf_country.xml#tf_co untry DISPLAY_ SEQ 1 2 3 4
11
12
13 21 22
1 2 2
2 2 2
3 1 2
23 31 32 33 41 42 43 431
Journals Items Unit Of Measures Goods Receipts Requisitio ns Purchase Order Reports Purchase Order List
2 3 3 3 4 4 4 43
2 2 2 2 2 2 1 2
3 1 2 3 1 2 3 1
Creating Business Components 2. Generate Entity object for ADF_MENU table (AdfMenu) 3. Right click AdfMenu Entity object and select the Default View Object context menu to create a View object for this entity and name it as AdfTopMenuView. 4. Modify the query of this View to add where clause for PARENT_MENU_ID IS NULL. 5. Similarly create another View object for this entity. Name it as AdfMenuView. This View (AdfMenuView) will provide data for second and subsequent levels in the tree menu. 6. Create a one to many View Link between AdfTopMenuView and AdfMenuView and name it AdfTopMenuViewLink1 7. Create a one to many self-referencing View Link with AdfMenuView on both sides of the link and name it as AdfMenuSelfViewLink2. 8. Create Application module and add the View instances as below AdfTopMenuView1 AdfMenuView1 (via AdfTopMenuViewLink1) AdfMenuView2 (via AdfMenuSelfViewLink2) This completes the ADF BC creation steps for our menu model. Creating Tree Menu This example is mainly based on the Oracle Dynamic Tabs Shell template and assumes that your main page is based on this template. If you are using any other template then create a dynamic region and created associated bean and name the bean as launcher and the class name as Launcher. The java code will be slightly different. This is documented at the end of this tutorial. 1. In the ViewController Project, open the page to which you are going to add the tree menu. 2. Create necessary Layout controls to contain your Tree Menu. 3. From the Data Control section drag the AdfTopMenuView1 View instance onto the layout container.
4. Tree binding editor will pop-up with the AdfTopMenuView1 already selected. Click the Add (+) button to add views for second and subsequent level. Note that the third level will be considered as self-referencing and will not be displayed in the binding editor. Ensure that all the required attributes are selected as display attributes for both levels. This will create the tree object with required data binding to the model that we created earlier. This will also create an outputText object which displays the menu name. 5. Select the outputText object and change the value from #{node} to #{node.Description} 6. Now we will need to add a commandLink object which can be used to launch taskflows. Drag a commandLink object from just below the OutputText object. Change the expression for the text property to #{node.Description}. 7. Now we have to objects which shows the same content (Description). Based on the MenuType value we are going to render only one out of these two. This is to avoid calling the task flow launcher program for main menu items. 8. For the rendered property of outputText set the expression as #{node.MenuType==1} 9. For the rendered property of commandLink set the expression as #{node.MenuType==2} 10. Now we will define the Action Listener for the command link. 11. In the Structure Window, select the first Link component. 12. Select the Property Menu for the ActionListener property. 13. Select Edit from the Property Menu. 14. In the Edit Property: ActionListener dialog, select launcher in the Managed Bean drop down. 15. In the Edit Property: ActionListener dialog, select launchTaskFlow in the Method drop down. 16. Click OK. 17. The Edit Property: ActionListener dialog will insert the following expression (EL): #{backingBeanScope.launcher.launchTaskFlow}. 18. In the Behavior section of the Property Inspector, change the PartialSubmit property to true. 19. Drag an Attribute (JSF.Core) component onto the CommandLink set the name as Definition and value as #{node.Definition} 20. Drag an Attribute (JSF.Core) component onto the CommandLink set the name as Description and value as #{node.Description}. This is used only in the case of Oracle Dynamic Tabs Shell template and can be skipped for other simple templates.
Modifying the launcher backing bean 1. Open Launcher.java in editor 2. Locate the code for the launchTaskFlow method.
3. Add the below code (in case of Oracle Dynamic Tab Shell template) UIComponent component = (UIComponent)actionEvent.getSource(); String title = (String)component.getAttributes().get("Description"); String taskFlow = (String)component.getAttributes().get("Definition"); _launchActivity(title, taskFlow, true); 4. Add the below code (in case of other template) UIComponent component = (UIComponent)actionEvent.getSource(); this.taskFlowId = (String)component.getAttributes().get("Definition");