Trace: • How to Use Client Actions
Client actions are defined as methods/functions that are automatically called at the client at a predetermined time, such as the click of a button, a switch between lines in a table, the insertion of a table, etc.
The action concept is based on Java´s listener concept and simplifies listener handling.
In JVx, the methods/functions used to define actions begin with event (e.g., eventAction). This facilitates the search for possible actions in javadoc and with IDE.
Usage
The definition of an action can be accomplished in two different ways. First, through the combination of object and method name:
/** * Initializes the UI components. */ private void init() { UIButton butCancel = new UIButton(); butCancel.setText("Cancel"); butCancel.eventAction().addListener(this, "doCancel"); } /** * Cancel action. */ public void doCancel() { dispose(); }
The following line
butCancel.eventAction().addListener(this, "doCancel");
defines that the method doCancel in the object this is executed upon clicking the cancel button.
In this example, the method
public void doCancel()
is defined without parameters and without a throws clause, since there are no respective requirements. However, the method could also be defined as follows:
public void doCancel(UIActionEvent pEvent) throws Exception
The parameter will only be passed on by JVx if it is included in the parameter description. If the throws clause is used, exceptions are caught by JVx and sent to the error dialogue. However, if specific error handling is required, a try/catch block has to be used and the throws clause has to be removed.
Since our action concept is based on the Java listener concept, it is also possible to use listeners:
butCancel.eventAction().addListener(new IActionListener() { public void action(UIActionEvent pActionEvent) { dispose(); } });
or
public class MyFrame implements IActionListener { public void action(UIActionEvent pActionEvent) }