Hammer functions are declared in XML syntax and
can be used to set data and perform other tasks. A function is declared using
It can accept arguments which we will see in some of the following exercises.
When a function is called, one or more
actions will be invoked.
Actions are basically tasks that run consecutively.
Actions can consume arguments,
local and model properties during execution.
There are several different ways to invoke functions depending on what is trying to be achieved. Functions and actions work congruently. Each function must have at least one action defined in order to work.
There is a detailed set of examples that demonstrates all the different was to declare and call functions.
timer Exercise: Declare a function that creates an alert box
Launch in your browser http://localhost:8080/sandbox/#/tutorials/functions/function_start . It should open a page with "Functions Tutorial" displayed.
This exercise will show you how to declare and call a function that displays an alert box.
Declare a function
First, we will declare a function with an action called
h:alert. Insert the following into the
<h:function name="onClick"> <h:alert>You clicked on the button!</h:alert> </h:function>
Calling our function
Widgets can invoke a function using
h:event. An event can be any user Mouse or Keyboard
interaction. In this
example, we will use a
click. Attach a
click to the button widget by
changing the the button widget
<h:button name="button" class="btn btn-default" label="Click Me"/>
<h:button name="button" class="btn btn-default" label="Click Me"> <h:event click="onClick"> </h:button>
In your browser, refresh your page. When you click on the button, you will see an Alert box open with the message.
Be sure to check out the detailed set of
examples for calling a function provided by the