220 likes | 242 Views
Learn how to customize data actions and data pages, access business services, and enhance application behavior with Oracle ADF Struts components.
E N D
Objectives • After completing this lesson, you should be able to do the following: • Describe data actions and data pages • Customize data actions and data pages to enhance the behavior of an application • Use data actions to access multiple types of business services • Describe the relationship between databound pages and data pages
What Are Data Actions? • Data actions are an extension of the action class, which: • Are provided with Oracle ADF • Provide access to business services, such as business components • Prepare the data and make it available for pages to consume
What Are Data Pages? • Data pages are an extension of the DataAction class, which: • Are provided with Oracle ADF • Combine a data action and a page forward • Do not rely on forwards to forward application data • Simplify the Page Flow Diagram
Utilizing Data Pages • To use a data page, perform these steps: 1. Create the data page in the Page Flow Diagram. 2. Double-click to create the corresponding view object (JSP, HTML, and UIX). 3. Define the Struts page flow as necessary. 4. Add business service methods to the data page as necessary.
Creating Data Pages • Drag a data page to the Page Flow Diagram. • /browseCustomer • The struts-config.xml file is updated with the data action. <action-mappings> <action path="/browseCustomers" className="oracle.adf.controller.struts.actions.DataActionMapping" type="oracle.adf.controller.struts.actions.DataForwardAction" name="DataForm" parameter="unknown"/> </action-mappings>
Creating the View Component • Double-click the data page to create the view component. • /browseCustomer <action-mappings> <action path="/browseCustomers" className="oracle.adf.controller.struts.actions.DataActionMapping" type="oracle.adf.controller.struts.actions.DataForwardAction" name="DataForm" parameter="/browseCustomers.jsp"> <set-property property="modelReference" value="browseCustomersUIModel"/> </action></action-mappings>
Displaying Data • To display data from the data page, add elements from the Data Control Palette: • Bound Data • Navigation • Operations • The data controls associated with the data action are defined in DataBindings.cpx (created automatically).
Displaying Data • Select elements from the Data Control Palette and drag them to the page: Generated code <c:forEach var="Row" items="${bindings.CustomersView1.rangeSet}"> <tr><td> <c:out value="${Row.CustomerId}"> </c:out></td>…
Modifying the Iterator • Click the UIModel icon in the Structure pane to locate the iterator for the model. Then use the Property Inspector to change the range size.
Adding Methods to Data Actions • To perform DML with data actions, add methods to the data action: Drag to data page icon • /browseCustomer • /addCustomer <action path="/addCustomers" … <set-property property="methodName" value="addCustomersUIModel.Create"/> </action>
Adding Methods to Data Pages • Drag and drop methods from the Data Control Palette to add methods to a data page: Create setCurrentRowWithKey Delete
Navigating in Data Pages • HTML Form tag submits to itself, by default. • Change the action to the page that receives the form data. • Use the Property Inspector to change the value of “action.” Select the data page or action that receives the form data.
Data Action Life Cycle 1. Initialize context Get HTTP request Get binding info 2. Build event list 8. Invoke custom methods 3. Check for model bindings 9. Refresh binding controls 4. Check if updates allowed 10. Dispatch to forward 5. Process updates 6. Validate updates 7. Handle model and UI events
Customizing Data Actions • Data action methods may be customized to provide functionality for: • A data action having two possible forwards: • Any custom functionality: protected ActionForward findForward(…) { Object s = request.getParameter("Update"); if (s != null) { return getActionMapping().findForward("success"); } else return getActionMapping().findForward("browse");} Protected void invokeCustomMethod(DataActionContext ac) { … }
Data Action Events • Built-in operations are listed in the UIModel.xml file: • Defined by: • Dragging operation from the Data Control Palette • Explicit creation in the Structure pane • Invoked by: • Button with the name “event_<operation>”, for example, event_Commit. • Hyperlink with a parameter “event=< operation>”, for example, event=Commit.
Data Action Events • Using built-in events, you can define your own operations: • Defined by: • Coding an on<CustEvent>() method in the data action • Invoked by: • Button with the name “event_<CustEvent>”, for example, event_Help. • Button with the name “event” and value <CustEvent>,for example, name=“event” value=“Help”. • Hyperlink with a parameter event=< operation>, for example, event=Commit.
on<Event> Example: Built-in Events • Extending a named built-in event ?event=commit public void onCommit(DataActionContext ctx) { HttpSession session = ctx.getHttpServletRequest().getSession(); Boolean loggedOn = (Boolean)session.getAttribute("AUTHFLAG"); if (loggedOn.booleanValue()) { ctx.getEventActionBinding().doIt(); } }
on<Event> Example: Custom Events • Calling a custom operation event=foo public void onFoo(DataActionContext ctx) { // just direct the flow to the "foo" forward ctx.setActionForward("foo"); }
Forwards and Events in ADF Applications • Name related forward components the same as the submit buttons to submit first to the data page, then to the forward target. • addCustomers.jsp: … <html:form action="/addCustomers.do"> … <input name="event_Add" type="submit" value="Submit"/> …
Summary • In this lesson, you should have learned how to: • Create data pages mapped to business services • Create Web applications that utilize data pages • Customize data actions and data pages to enhance the behavior of an application
Practice 12-1: Overview • This practice covers the following topics: • Creating data actions • Adding methods to data actions