Sei sulla pagina 1di 35

Create a New OA Workspace and Empty OA Project with the New Dialog

Step 2: Create the OA Component Page

JDeveloper creates your top-level page layout region for you automatically when you create your page.

Step 3: Modify the Page Layout (Top-level) Region

Set the ID property to PageLayoutRN. Verify that the Region Style property is set to pageLayout. Verify that the Form property is set to True. Verify that the Auto Footer property is set to True. Set the Window Title property to <your name>: Hello World Window Title. This becomes the window title for the page. Set the Title property to <your name>: Hello World Page Header. Set the AM Definition property to oracle.apps.fnd.framework.server.OAApplicationModule (you will have to type in the value). This is a generic application module supplied by the OA Framework.

Step 4: Create the Second Region (Main Content Region) Create your second region under the page layout region by selecting the page layout region in the Structure window and choosing New > Region from the context menu. Replace the default value in the ID property with MainRN. Set the Region Style property to messageComponentLayout (this provides an indented single- or multiple-column layout for the child items of the region).

Step 5: Create the First Item (Empty Field) Create your first item under the second region (main content region) by selecting the second region in the Structure window and choosing New > messageTextInput from the context menu. This item will take any name as parameter.

Set the ID property to HelloName. Verify that your Item Style property is set to messageTextInput (this style provides a text label and an input field). Set the Prompt property to Name. Set the Visual Length to 20. Set the Data Maximum Length to 50.

Step 6: Create a Container Region for the Go Button To add a non-message-type bean such as a submitButton to a messageComponentLayout region, you must first add the bean to a messageLayout region. Select the messageComponentLayout region and select New > messageLayout.

Name this region ButtonLayout. Step 7: Create the Second Item (Go Button) Create your Go button item by selecting the messageLayout region, ButtonLayout, in the Structure window and choosing New > Item from the context menu. Set the following properties for your button item: Set the value of the ID property to Go. Set the Item Style property to submitButton. Set the Attribute Set property to /oracle/apps/fnd/attributesets/Buttons/Go.

Step 8: Save Your Work (Save-All) Step 9: Run Your Page Using the Run Option You can try out your page using the Run option on the context menu. If you are using a database other than what you already have in your project settings, you will need to modify the Runtime Connection project settings by selection your project file and choosing Project Properties from the main menu. Specifically, you must use a combination of Username, Password, (Responsibility) Application Short Name and Responsibility Key that is valid for your database to enable your session to log in. The output will be like:

Here the Go Button has no functionality. Now to add some functionality to this Button, we need to add a Controller.

Step 10: Add a Controller Add a controller to display a message when the user clicks on the Go button. Select your second region (MainRN) and choose Set New Controller from the context menu.

Step 11: Edit Your Controller

When you create a controller .java file will be automatically created and it will contain below 2 methods. public void processRequest(OAPageContext pageContext, OAWebBean webBean) { } public void processFormRequest(OAPageContext pageContext, OAWebBean webBean) { }

Now you need to add the below code in the java file to add the required functionality. Add the following line as the last line of the import section to make the OA Framework OAException routines available:

import oracle.apps.fnd.framework.OAException;

Add the below code in processFormRequest method

if (pageContext.getParameter("Go") != null) { String userContent = pageContext.getParameter("HelloName"); String message = "Hello, " + userContent + "!"; throw new OAException(message, OAException.INFORMATION); } Step 12: Build Your Controller Build your controller by selecting Rebuild from the context menu within the code editor window. Step 13: Test Your Work Using the Run Option Save your work, and then test it using the Run option. Type something into your field and then click the Go button. You should see the page with an informational message that contains what you typed into the field, as shown:

Build Simple Search Page in OAF Step1: Build a Create Button Select the view EmpSearchPG, right click and select New > TableActions. One region (region1) will be created with region style as FlowLayout. Change the ID of the above newly created region to ButtonLayoutRN. Right click ButtonLayoutRN and create a new Item. Set the below details for the Item o ID :Create o Item Style : submitButton o Attribute Set: /oracle/apps/fnd/framework/toolbox/attributesets/FwkTbxEmployees/CreateEmployee o Action Type: fireAction o Event: create

Step 2: Set a Controller Right click PageLayoutRN and select Set New Controller. Give the package name as xxhci.oracle.apps.custom.LabExamples.webui. Give the class name as EmpSearchCO.

Add the following logic to processFormRequest of EmpSearchCO.java after super.processFormRequest method. if (pageContext.getParameter("event").equalsIgnoreCase("create")) { System.out.println("EmpSearchCO: processing create/update"); pageContext.setForwardURL("OA.jsp? page=/xxhci/oracle/apps/custom/LabExamples/webui/EmployeeCreatePG", null, OAWebBeanConstants.KEEP_MENU_CONTEXT, null, null, true, OAWebBeanConstants.ADD_BREAD_CRUMB_YES, OAWebBeanConstants.IGNORE_MESSAGES); } You might get red lines under java classes which are not imported. Bring the cursor on these red-lined text and click Alt+Enter (JDev automatically tells you to import the class using Alt+Enter when you move cursor over these lines). Step 3: Build the Create Employee Page (EmployeeCreatePG) Right click on Project >New >Web Tier >OA Components Page. Set the Page name as EmployeeCreatePG Set the package name as xxhci.oracle.apps.custom.LabExamples.webui

Select the pageLayout region of EmployeePG and assign the properties as below ID : PageLayoutRN

AM Definition : xxhci.oracle.apps.custom.LabExamples.server.XxhciOafTrngEmpTabAM Window Title : Employee Window Title: Employee Warn About Change: True

Step 4: Add items to Create Employee Page Create a region under PageLayoutRN and assign ID as PageButtonsRN. Set the region style as pageButtonBar Now we need to create two buttons in this region as APPLY and CANCEL.

For Apply Button: Right click on PageButtonsRN > New > Item. Set the properties as ID :Apply Item Style :submitButton Attribute Set : /oracle/apps/fnd/attributesets/Buttons/Apply Additional Text :Click to save the transaction Action Type: fireAction Event: Apply For Cancel Button: Right click on PageButtonsRN > New > Item. Set the properties as ID : Cancel Item Style : submitButton Attribute Set :/oracle/apps/fnd/attributesets/Buttons/Cancel Additional Text : Click to cancel the transaction Action Type: fireAction Event: Cancel For text items in page: Right click on PageLayoutRN New Region using wizard. Enter data as shown in below screenshots

Step 4.1: Select AM and VO instance created during search page

Step 4.2: Give Region ID as MainRN and Region Style as defaultSingleColumn

Step 4.3: Select attributes as below (EmpNo, EmpName and Department)

Step 4.4: Change the prompts of items as shown below (messageInputText)

Click on finish for step 5. Change the Region Style for MainRN to messageComponentLayout. This is done now as above region wizard, doesnt have support for messageComponentLayout. Click on Yes button when the confirm window pops for change of region style. Step5: Adding Model Layer Code Add following code to XxhciOafTrngEmpTabAMImpl.java. Add import statements at the start and rest of the methods with the class definition. import oracle.jbo.Row; import oracle.apps.fnd.framework.OAViewObject; import oracle.jbo.Transaction; import oracle.jbo.domain.Number; import oracle.jbo.RowSetIterator; // Creates a new employee. public void createEmployee() { OAViewObject vo = (OAViewObject)getXxhciOafTrngEmpTabEOView1(); // Per the coding standards, this is the proper way to initialize a // VO that is used for both inserts and queries. See View Objects // in Detail in the Developer's Guide for additional information. if (!vo.isPreparedForExecution()) { vo.executeQuery(); } Row row = vo.createRow(); vo.insertRow(row); // Required per OA Framework Model Coding Standard M69

row.setNewRowState(Row.STATUS_INITIALIZED); } // end createEmployee() // Executes a rollback including the database and the middle tier. public void rollbackEmployee() { Transaction txn = getTransaction(); // This small optimization ensures that we don't perform a rollback // if we don't have to. if (txn.isDirty()) { txn.rollback(); } } //Commits the transaction. public void apply() { getTransaction().commit(); } Add the following import statement and modify the create method in XxhciOafTrngEmpTabEOImpl as follows: Add this as a part of import statements import oracle.apps.fnd.framework.server.OADBTransaction; Modify the create method as below public void create(AttributeList attributeList) { super.create(attributeList); OADBTransaction transaction = getOADBTransaction(); Number employeeId = transaction.getSequenceValue("FWK_TBX_EMPLOYEES_S"); setEmpNo(employeeId.toString()); } Step6: Add Controller logic for Create Employee Page Right click on PageLayoutRN of EmployeeCreatePG > Set New Controller. Give the values as Package : xxhci.oracle.apps.custom.LabExamples.webui Class Name : EmployeeCO Add the below code to the new CO Import Statements: import java.io.Serializable; import oracle.apps.fnd.common.MessageToken; import oracle.apps.fnd.framework.OAApplicationModule; import oracle.apps.fnd.framework.OAException; import oracle.apps.fnd.framework.OAViewObject; import oracle.apps.fnd.framework.webui.OADialogPage; import oracle.apps.fnd.framework.webui.OAWebBeanConstants; processRequest (after super.processRequest): if (!pageContext.isBackNavigationFired(false)) {

OAApplicationModule am = pageContext.getApplicationModule(webBean); am.invokeMethod("createEmployee"); } else { // We got here through some use of the browser "Back" button, so we // want to display a stale data error and disallow access to the OADialogPage dialogPage = new OADialogPage(STATE_LOSS_ERROR); pageContext.redirectToDialogPage(dialogPage); } processFormRequest (after super.processFormRequest): OAApplicationModule am = pageContext.getApplicationModule(webBean); // Pressing the "Apply" button means the transaction should be validated // and committed. if (pageContext.getParameter("event").equalsIgnoreCase("Apply")) { OAViewObject vo = (OAViewObject)am.findViewObject("XxhciOafTrngEmpTabEOView1"); String employeeName = (String)vo.getCurrentRow().getAttribute("EmpName"); String employeeNum = (String)vo.getCurrentRow().getAttribute("EmpNo"); am.invokeMethod("apply"); MessageToken[] tokens = { new MessageToken("EMP_NAME", employeeName), new MessageToken("EMP_NUMBER", employeeNum) }; OAException confirmMessage = new OAException("AK", "FWK_TBX_T_EMP_CREATE_CONFIRM", tokens, OAException.CONFIRMATION, null); pageContext.putDialogMessage(confirmMessage); pageContext.forwardImmediately("OA.jsp? page=/xxhci/oracle/apps/custom/labExamples/webui/EmpSearchPG", null, OAWebBeanConstants.KEEP_MENU_CONTEXT, null, null, true, OAWebBeanConstants.ADD_BREAD_CRUMB_NO); } // If Cancel button is pressed, rollback the transaction else if (pageContext.getParameter("event").equalsIgnoreCase("Cancel")) { am.invokeMethod("rollbackEmployee"); pageContext.forwardImmediately("OA.jsp? page=/xxhci/oracle/apps/custom/labExamples/webui/EmpSearchPG", null, OAWebBeanConstants.KEEP_MENU_CONTEXT, null, null, false, OAWebBeanConstants.ADD_BREAD_CRUMB_NO); }

Step 7: Save all and Run the EmpSearchPG to test the page

The Final Output:

4 Comments Posted by Dibyajyoti Koch on May 29, 2011 in OA Framework Tags: How to build a Create Page in OAF, OA Framework, OAF, OAF Components Build simple search page in OA Framework 26 May Here are the steps to create a simple search page in OA Framwork. I have used OAF Version 12.1.1 for this exercise. There are many ways to do this and here I have followed one of these. Step 1: Create a Package All BC4J model components must belong to a Business Components (BC4J) package. So create a package with a name like xxhci.oracle.apps.custom.LabExamples.server.

Step2: Create an Entity Object (EO) Entity objects encapsulate business logic and DML operations for application tables.

To create a new entity object in the above defined Business Components (BC4J) package: 1. In the JDeveloper Navigator, select the BC4J package where you want to create your entity object. 2. Right click and select New Entity Object 3. Do the following steps to create an EO. 2.1 Specify a Schema Object (the exact name of the table for the entity object)

2.2 In the Attributes page (Step 2 of 5), you should see all the columns in the table that you specified in the Name page.

Select New to create a transient attribute that is used in the business logic, such as a calculated OrderTotal in a purchase order that is used for approval checking. 2.3 In the Attribute Settings page (Step 3 of 5), verify or set the following information for each of the entity objects attributes:

The Attribute and Database Column Name and Type properties default correctly from the table definition. For primary key columns, ensure that the Primary Key and Mandatory checkboxes are selected. For columns that are never updateable, or updateable only when new, select the appropriate Updateable radio button. For columns whose values change after database triggers execute, select the Refresh After update or insert as appropriate. 2.4 In the Java page (Step 4 of 5) page: Check the option for generating an Entity Object Class. In the Generate Methods box, opt to generate Accessors, a Create Method and a Remove Method.

2.5 Click on Generate default view object to create a VO. Select Finish to save your entity object definition and implementation. BC4J will create an XML definition file and a Java implementation file for your entity object.

Step3: Create an View Object (VO) If you click Generate default view object tab as mentioned above, you dont have to create a VO separately. If you forgot this, you have to create a VO. Click on the VO to test the SQL Statement generated by the EO and check in the Expert Mode.

Step4: Create a New Application Module (AM) To create a new application module in a Business Components (BC4J) package: 1. In the JDeveloper Navigator, select the BC4J package where you want to create your application module. 2. From the main menu, choose File > New to open the New Object Gallery.

Select the view object.

In the Java page (Step 4 of 5), deselect the Generate Java File(s) checkbox ONLY if you are certain that you wont be writing any code for your application module (you can always delete the class later if you find that you dont need it, so its probably best to simply generate it at this point unless you are creating a simple container for LOV view objects).

Select Finish to create your application module. BC4J will create an XML definition and implementation file. Step5: Create a Page (EmpSearchPG) Create the EmpSearchPG page as follows Right click on project New Web Tier OA Components Page Give the Page Name as EmpSearchPG and package as xxhci.oracle.apps.custom.LabExamples.webui Select region1 page from Structure Window and change its properties as ID PageLayoutRN Select the AM Definition as xxhci.oracle.apps.custom.LabExamples.server.XxhciOafTrngEmpTabAM Give a Window Title as Employees Search Window Give a Title as Employees

Step6: Add a Query region and Results table Right click on PageLayoutRN New Region. Set the properties of the new region as ID QueryRN Select the Region Style as query and Construction Mode as resultBasedSearch. Right click on QueryRN region on structure navigator New Region using wizard. Select the AM and VO which we have created in earlier steps as shown in below figure.

Set the Region Style as Table

Change the Prompt and Style for all three items.

Step7: Changes the Item Properties

Go to EmpNo item and set the Search Allowed property to true. Similarly do the steps for EmpName and Department also.

St ep8: Save all changes (Save All). Step9: Run the Page (EmpSearchPG) Creation of search page is complete. Run the EmpSearchPG to test the page. If everything works fine for you, you should able to view an output like below:

Potrebbero piacerti anche