Entering content frame

Procedure documentation Dynamically Creating Pushbuttons with Corresponding Actions

 

If the maximum number of pushbuttons is not known at design time, you can create these at runtime together with the corresponding action. Since it is not possible to dynamically create event handlers in the view controller, dynamically created actions must use an event handler declared already at design time. Mapping an event parameter from the event source (the user interface element) to the signature of the event handler in the view controller is termed as Parameter Mapping in the Web Dynpro.

 

Procedure

       1.      To dynamically add pushbuttons from the Container-UI-Element ActionContainer, enter the following program code into the method wdDoModifyView underneath the first for loop.

wdDoModifyView()

   ...

 

      // add UI elements to container

      theGroup.addChild(theLabel);

      theGroup.addChild(theUIElement);            

    }

              

    // The buttons are displayed within the container the

    // "actionContainer"

    IWDTransparentContainer theActionContainer =

       (IWDTransparentContainer)view.getElement( 

                                            "ActionContainer");

    // loop through all actions

    for (int index = 0; index < theBackend.getNumberActions();

         index++)

    {

       // get action meta data

       SomeBackEnd.OperationDescriptor op =

          theBackend.getAction(index);

 

       // Create button and set some attributes      

       IWDButton theButton = (IWDButton)view.createElement(

           IWDButton.class, "btn"+index);

       theButton.setTooltip(op.getTooltip());

       theButton.setText(op.getDisplayText());

        

        // To be continued...

         

 

      theActionContainer.addChild(theButton);           

       }

    }

    //@@end

  }

Note

The pushbuttons should be entered in the ActionContainer already statically declared.

This graphic is explained in the accompanying text Error source: The container for actions must contain the ActionContainer ID. (see also the Properties view in the layout editor).

You will find information on the pushbuttons in the theBackend object.  Through getNumberActions(), you get the number of pushbuttons to be created, and through getAction() you get information on each action.  In this way, an ID, a quick info, and a text can be assigned to each pushbutton.

 

So far, all the required pushbuttons have been created. However, these do not yet contain any actions or event handlers. Event handler cannot be dynamically created in the Web Dynpro, but only statically defined. For this reason, statically define the following action handler for the various pushbuttons:

 

       2.      Switch to the Actions tab page.

       3.      Choose the New pushbutton and enter GenericAction as the name. Choose Next to confirm your entries.

       4.      Assign a parameter to the action by choosing New. Enter Command as the name and choose string  as type. Confirm with Finish.

       5.      Switch to the Implementation tab page.

       6.      Um einen neue Aktion anzulegen und diese gegen einen Drucktaste zu binden, fügen Sie in wdDoModifyView() folgenden Programmcode hinzu:

wdDoModifyView()

         theButton.setText(op.getDisplayText());

        

         // Create an action. This becomes important in case

         // the enabling state of buttons using the same event

         // handler should be different. The enabling state of

         // a button is controlled by action.isEnabled. Thus

         // it is possible to have several actions pointing to

         // the same event handler but using different enabling

         // states.

         IWDAction theAction = wdThis.wdCreateAction(

            IPrivateDynamicView.WDActionEventHandler

               .GENERIC_ACTION,

            "");

         theButton.setOnAction(theAction);

        

         // The event handler has to know which button was

         // pressed since we only have a single generic

         // event handler. By means of parameter mapping we can

         // supply an individual parameter for each button

         // to the event handler.

         theButton.mappingOfOnAction().addParameter(

            "Command",op.getName());

 

         theActionContainer.addChild(theButton);           

       }

    }

    //@@end

  }

Note

Using wdThis.wdCreateAction( eventhandler, text), you can create a new action. An event handler and a text must be passed to this action. Since the event handler cannot be created dynamically, the event handler declared statically onActionGenericAction beforehand is assigned.

Using setOnAction(…), the dynamically created action is assigned to the onAction event of the pushbutton user interface element.

To differentiate between the pushbuttons, the Command parameter is added to the onAction event of the pushbutton UI element: theButton.mappingOfOnAction().addParameter("Command", op.getName()). The value of the additional event parameter Command is passed from the Web Dynpro runtime environment to the parameter with the same name in the action event handler onActionGenericAction.

 

Next step:

Action Handling

  

 

 

Leaving content frame