Friday, 20 September 2013

Hello World in ADF

With Java Basics up your sleeves, you are ready for the "Hello World" of ADF. We will create a Page with an Input Text and a Button.

Activity: We will create a Page with an Input Text with label Name and a Button. On pressing the button message will appear on the top of the Page greeting the user.

The final page should look like below:



Create a "Fusion Application" with name as Hello, chose default values which will create a Model and ViewController project as below.


Now lets create a page on which we will create an InputText and a Button. Right Click on ViewController ->Web Tier-> JSF Page. Enter the name as HelloWorld and make sure that no Managed Bean is selected as shown below.


On the page drop an OutputFormatted, InputText and a Command Button. The page should look like below:



In the Source View, it should look like below:


Now, we need to handle the event on the button and modify the Output Text programmatically. To achieve that we need to create a Managed Bean which is used to gain access (and change) to the values on the Page. Select Output Text and chose the Binding property 


Chose Bean Name as MB and Class Name as "HelloManagedBean", package as "com.hello.mb"


Chose property as OutputMessage as shown below:


Similarly create a Binding for InputText. Chose MB as Managed Bean and name as "nameTextArea".
Click Ok and this will create a Class with Getter and Setter methods automatically created which will be used to get and the values programmatically on Button Click.

Now, we have to handle the Button Click event and take the values of Input Text and display the value in Output Text. Double Click the Button and chose MB as managed bean and let Method be cb1_method as shown below.


This value will be set on the Binding of the CommandButton as #{MB.cb1_action}
This will open the Managed Bean, type the following code in the method cb1_action 

    public String cb1_action() {
        // Add event code here...
        
        RichInputText helloString = getNameTextArea();
        outputMessage.setValue("¡ Hola "+ helloString.getValue().toString() +" !");
        
        return null;
    }


Here is the Screenshot for reference.


Now run the page.

No comments:

Post a Comment