Auto-Wiring for Actions
Auto-Wiring for Actions
The most important responsibility of a controller is to handle user actions. For example, when the user clicks on the Next button, the controller might call a workflow rule to save or get some data, update the UI controls, or select another tab page.
You can define functions that handle user actions in the Controller:
var addEmployeeController = View.createController('addEmployee', {
...
// event listener function for the Next button click event
employeeForm_onNext: function() {
this.employeeTabs.selectTab('Parking');
}
});
You can register your new function as a listener for the Next button
click
event:
afterViewLoad: function() {
// add the callback function as a listener to the Next button
this.employeeForm.addActionListener('next', this.employeeForm_onNext, this);
}
However, the
addActionListener()
call is another example of "boilerplate" code that only makes the application code less clear. If the event listener function name matches the "
panelId_actionId
" pattern, as shown above, your controller will automatically call it, and you can skip the
addActionListener()
call:
afterViewLoad: function() {
// no extra code is required here because...
},
// ...this event listener is auto-wired due to naming convention
employeeForm_onNext: function() {
this.employeeTabs.selectTab('Parking');
}