!--a11y-->
Action Handling
In SomeBackEnd.java, there are two pushbuttons – Save and Delete. For reasons of simplicity, the functions are known at design time and can thus be implemented in the event handler onActionGenericAction().
If the user confirms an action by clicking Save, a log that displays the data he entered is to appear beside the input fields.

If the user clicks Delete, the user inputs are deleted and the log will disappear.

The user interface elements for the log were already declared statically. Only their visibility changed.
So that the contents of the log, are displayed, a context attribute for storing the text is declared.
To change the visibility properties of the log, an additional context attribute of the Visibility type is required.
...
1. Switch to the Context tab page.
2. Create the following context attributes:
Context Element |
Type |
Property |
Value |
Result |
Value attribute |
type |
string |
Visible |
Value attribute |
type |
com.sap.ide.webdynpro. uielementdefinitions.Visibility |
3. Switch to the Layout tab page.
4. Select the interface element ProtocolGroup (RootUIElementContainer à ProtocolGroup)
5. In the Properties view, bind the property visible to the context attribute Visible.

6. Select the interface element result (RootUIElementContainer à ProtocolGroup) à result).
7. In the Properties view, bind the property visible to the context attribute Visible.
8. At the beginning, the ProtocolGroup should not be made visible in the application. For this reason, set the visibility property in the wdDoInit() method to false.
9. Switch to the Implementation tab page and add the following program code in wdDoInit():
wdDoInit() |
... wdContext.currentContextElement().setVisible(WDVisibility.NONE); //@@end } |
The onAction event for the pushbuttons Save and Delete is handled in the view controller of the onActionGenericAction() method. Due to the parameter mapping performed in the step Dynamically Creating Pushbuttons with Corresponding Actions, the value of the Command parameter depends on which pushbutton was operated. If Save was chosen, the Command is “save”; if Delete was chosen, the Command is “delete".
Both during reading and deleting user inputs, dynamically created context attributes and context nodes must be accessed. For this purpose, the IDs stored in the object of the type SomeBackEnd are required.
10. Add the following program code to the event handler onActionGenericAction():
onActionGenericAction() |
public void onActionGenericAction( com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent, java.lang.String Command ) { //@@begin onActionGenericAction(ServerEvent) SomeBackEnd theBackend = new SomeBackEnd(); SomeBackEnd.FieldDescriptor fld;
IWDNode node = wdContext.currentContextElement().node() .getChildNode("DynamicNode", 0); IWDNodeElement nodeElement = node.getCurrentElement();
if(Command.equals("save")){ //To be continued }
else if(Command.equals("delete")){ //To be continued } //@@end } |

The basic frame for the event handler onActionGenericAction() is defined.
Error
sources:
i. The context node must have been named exactly (DynamicNode) during dynamic creation.
ii. During parameter mapping, the value save or delete must have been assigned to the parameter Command.
11. Implement the functions for Save by adding the following program code in the block if(Command.equals(„save“)):
onActionGenericAction() |
... if(Command.equals("save")){ String result = "Your data was successfully saved:" + "\n\r\n\r"; for (int index = 0; index < theBackend.getNumberFields(); index++) { fld = theBackend.getField(index); Object value = nodeElement .getAttributeValue(fld.getName()); if (value == null) value = "<null>" ; result = result + fld.getName() + " : " + value.toString() + "\n\r"; } wdContext.currentContextElement() .setVisible(WDVisibility.VISIBLE); wdContext.currentContextElement().setResult(result); } else if(Command.equals("delete")){ ... |

In the result string, the log for the user input is stored. This value is stored in the last step in the Result context attribute.
So that the user input is read, the dynamically created context attributes are used for iteration; these were determined by the number of user interface elements. Through the call of the generic method getAttributeValue(String name) of the interface IWDNodeElement, the value of the required context attribute can be accessed.
Error
source: the context attribute must have been named exactly during dynamic
creation.
So that the user interface element named ProtocolGroup is displayed, the context attribute Visible is set to visible (WDVisibility.VISIBLE).
12. Implement the functions for Delete by adding the following program code in the block else if(Command.equals("delete") to the following program code:
onActionGenericAction() |
... else if(Command.equals("delete")){ for (int index = 0; index < theBackend.getNumberFields(); index++) { fld = theBackend.getField(index); nodeElement.setAttributeValue(fld.getName(), fld.getInit()); } wdContext.currentContextElement() .setVisible(WDVisibility.NONE); } //@@end } |

To delete the user inputs and set the input fields to initial value. The dynamically created context attributes are again used for iteration and the value is reset.
Error
source: the context attribute must have been named [fld.getName()] during dynamic creation.
The log is again set to invisible by assigning the value WDVisibility.NONE to the context attribute Visible.
Next step:
Executing the Application TutWD_Dynamic_Init
