!--a11y-->
Event Parameter and Parameter
Mapping 
Action event handlers are independent from the UI element that was used to trigger an event. They are independent, because a UI element event is bound to the event handler of an action and this event handler uses an instance of the action class.
Parameters can be passed to certain UI element events. For example, the onSelect event of the DropDownByIndex UI element contains the parameter index.
These event parameters are not defined in the event source - that is, the UI element - but in the implementation of the event handler. Therefore, the implementations in the controller remain independent from the UI element.
If an action is bound to such a UI element, it is also specified which event parameters are to be used as the parameters for the action event handler. This process is known as parameter mapping. It is the mapping of event parameters in the event source, the UI element, to the signature of the event handler.
This is needed, for example, if you want to replace a table with a dropdown list box without modifying the source code of the event handler in the controller. The onLeadSelect event, which occurs when a table cell is selected, provides the parameters col and row. The onSelect event of a dropdown list box contains the parameter index. If you want to exchange the UI elements, you must define a parameter mapping (see example).
The parameter mapping represents an instance of the UI element event. Therefore, the parameter mapping is defined at UI element level. The wdDoModifiyView method is provided to describe the parameter mapping of a UI element event.
The following source code example provides the UI element and the corresponding parameter mapping:
|
public static void wdDoModifyView(IPrivateMyView wdThis, IPrivateMyView.IContextNode wdContext, IWDView view, boolean firstTime) { //@@begin wdDoModifyView if (firstTime) { // Access UI element with id “theTable” IWDTable theTable = (IWDTable) view.getElement("theTable");
// Map parameter row to parameter newSelection. We do not care // about the second parameter “col” also defined for UI event // OnLeadSelect theTable.mappingOfOnLeadSelect(). addSourceMapping("row","theNewIndex"); } //@@end } |
If you replace the table with a DropDownByIndex UI element, you can use the same action event handler without modifying it. However, you must redefine the parameter mapping, because the DropDownByIndex UI element triggers the event onSelect, and this event contains the parameter index.
|
public static void wdDoModifyView(IPrivateMyView wdThis, IPrivateMyView.IContextNode wdContext, IWDView view, boolean firstTime) { //@@begin wdDoModifyView if (firstTime) { // Access UI element with id “theTable” IWDDropDownByIndex theDropDown = (IWDDropDownByIndex) view.getElement("theDropDown");
// Map parameter index to parameter newSelection. theDropDown.mappingOfOnSelect(). addSourceMapping("index","theNewIndex"); } //@@end } |
You can also map constants using parameter mapping.
In a Web Dynpro application, you can create different buttons at runtime whose maximum number cannot be specified at design time. You can create the buttons and the actions at runtime. However, you can bind all dynamically created buttons to a single action event handler. This special function is based on constant mapping. Without having a reference to a runtime information of the UI element in an action event handler, a Web Dynpro application can determine which button the user selected. This is possible, because constant parameters are mapped to an action event handler.
The event handler can read these parameters and therefore determine which UI element triggered the event. You can replace a button with a link without having to change the source code in the event handler. See the following example source code:
|
public static void wdDoModifyView(IPrivateMyView wdThis, IPrivateMyView.IContextNode wdContext, IWDView view, boolean firstTime) { //@@begin wdDoModifyView if (firstTime) { for (int index = 0;index < 10;index ++) { IWDButton theButton = (IWDButton) view.createElement(IWDButton. class,"theButton"+index);
theButton.setText(getSomeText(index)); theButton.setOnAction(wdThis.wdGetGenericAction()); theButton.mappingOfOnAction().addParameter("commandId",index); } } //@@end }
/** declared validating action event handler */ public void onGenericAction (IWDCustomEvent wdEvent , int commandId ) { //@@begin onGenericAction(ServerEvent) switch(commandId) { case 0: ExecuteCommand_1(); break; case 1: ExecuteCommand_2(); break; ... } //@@end } |
See IWDParameterMapping.
