Saturday, 4 May 2013

16. Controller Extension in OAF

Here is a simple example to show personaliztion and controller extension.

I have extended the functionality of HelloWorldPG .

Seeded functionality of this page is:
User will enter his name or any text and on press of 'Go' button, the page will show a message by append 'Hello, ' in front of the name entered. If user click on button without entering anything in text field, still page will show a message 'hello, '.
Below is screenshot for the same:

Now we do these changes:
1) Using personalization, we will modify the prompt of text field (from 'name' to 'Enter Your Name: ').
2) Using controller extension, we will modify the message as : 'hello, ' + name + 'The message is from custom controller.'. Also we put a validation that name filed should not be empty while clicking on 'Go' button.

Below are steps for the same:

1) Create a new java class extending from standard controller.
Right click on xxcus --> new --> java class.
Enter the details as shown below:

The package for custom controller must follow standard conventions as:

2) Write the below code in custom controller:


import oracle.apps.fnd.framework.OAException;
import oracle.apps.fnd.framework.toolbox.tutorial.webui.HelloWorldMainCO;
import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;

// here we are extending from HelloWorldMainCO
public class XxcusHelloWorldMainCO extends HelloWorldMainCO {

    public void processFormRequest(OAPageContext pageContext, 
                                   OAWebBean webBean) {

     if (pageContext.getParameter("Go") != null) {
         String name = pageContext.getParameter("HelloName");
         if (!("".equals(name.trim()))) {
           String message = 
            "Hello, " + name + " This message is from custom controller.";
           throw new OAException(message, OAException.INFORMATION);
     } else {
        throw new OAException("Please enter your name.", 

3) Compile and move to server:
Compile the file and move the class file to unix box at 

4) Attach this custom controller to your page:
Open HelloWorld page and click on 'Personalize Page' at the top right. This will show a page as below. Click on personalize pencil against the 'Message Component Layout: (MainRN)':

Change the controller property as shown below and click on apply:

5) Change prompt of text field:
Click on personalize pencil against Message Text Input: Name.

Here change the prompt property to 'Enter Your Name: ' at site level as shown below and click on 'Apply':

Finally, click 'Return to Application' link and all is done. Enter your name and press 'Go' button. It will show our custom message :

Also, the page will show error message if Go button is pressed when the field is empty:

No comments:

Post a Comment