The goal of this tutorial is to learn how to use input components such the inputbox and the combobox.
The application that we are going to develop is an improvement of The Hello World Deluxe: This application will ask the user to input some information in order to show a customized 'Hello world' message.
What we are going to do in this tutorial is:
To modify the helloWorld template by adding 4 components: an inputbox, a combobox, a button and a label (templates/helloWorld.tpl)
To modify the event handler associated to the helloWorld view (libs/eventhandlers/HelloWorldEventHandler.class.php)
Placing input components within the template
First thing to do will be to modify the template helloWorld.tpl by adding the following components:
As we can see, we have declared 4 components: an inputbox (nameInputBox), a combobox (saludationComboBox), a commandbutton (sayHelloButton) and a label (helloLabel).
What we expect is to see a customized 'Hello World!' message like 'Hello mr. Antuan' when click on the button.
Modifying the event handler
The following task to do is to adapt the event handle to:
Read user input from components
Build a customized 'Hello World!' message and show it
To do that, we have to define a method to handle the button click event and perform those tasks:
As we can see in the listing above, we have just retrieve the value of the input components by calling the getValue method.
All the input components inherit from the __InputComponent, exposing the getValue method to retrieve the current value of each one
Analogous, all those kind of components exposes another method (setValue) to set a new value.
Executing the Hello World Pro
Now it's time to execute our application. Just type the following url: http://yourdomain/pathtoyourapplication/helloWorld.html
The aspect of our application should be like the following figure once we have click on the button:
And again: No need to refresh the entire page to show the hello message. Ajax + Json instead of, which is handled automagically by the framework.