Start of Content Area

Background documentation Dynamic UI Generation  Locate the document in its SAP Library structure

Web Dynpro enables you to statically declare objects at design time. This considerably reduces the programming effort. Dynamic UI Generation, however, enables you to develop programming sequences declared at design time and to develop source code that overwrites existing declarations.

Dynamic Modification of a View

Web Dynpro provides the wdDoModifyView Hook method in the controller implementation of the view. In this way you can add source text to the controller implementation of the view in order to program the parts of the user interface that are not yet known at design time. This could be for example configuration-driven parts of the user interface. The wdDoModifyView method is called for every view before it is displayed on the screen. The wdDoModifyView method was defined as a static method because you want to prevent  the application development from routinely creating references to UI elements in class variables in order to access for example event handlers. It should only be used to modify a view and therefore should not contain any source text that references controllers. The method is used to modify UI elements of a view in order to enhance the possibilities for UI development at design time. For example, the Hook method is used if a UI element is to be rendered only at runtime.

You can find an example under Dynamic Generation of a User Interface Element.

/**

   * Hook method called to modify a view just before rendering.

   * This method conceptually belongs to the view itself, not to the

   * controller (cf. MVC pattern).

   * It is made static in order to discourage a way of programming that

   * routinely stores references to UI elements in instance fields

   * for access by the view controller's event handlers etc.

   * The Web Dynpro programming model recommends to restrict access to

   * UI elements to code executed within the call to this hook method!

   *

   * @param wdThis generated private interface of the view's controller as

   *        provided by Web Dynpro; provides access to the view controller's

   *        outgoing controller usages etc.

   * @param wdContext generated interface of the view's context as provided

   *        by Web Dynpro; provides access to the view's data

   * @param view the view's generic API as provided by Web Dynpro;

   *        provides access to UI elements

   * @param firstTime indicates whether the hook is called for the first time

   *        during the lifetime of the view

   */

  public static void wdDoModifyView(IPrivate<view name> wdThis, Iprivate<view name>.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)

  {

    //@@begin wdDoModifyView

    //@@end

  }

Parameter firstTime specifies whether the Hook method was called for the first time during the lifetime of the view.

Note

Note that the implementation of the wdDoModifyView method must always be defined between the comment lines //@@beginand //@@end, which is the user coding area. Otherwise, a runtime error occurs.

Caution

You should not define any class variables such as private static IWDView myView in the areas //@@begin others and //@@end of the controller implementation and then use the source text in the wdDoModifyView method as follows: myView = view;. With this source text, no copy of view is created. The reference to myView is overwritten with the reference to view so that there are two references to view. The source text myView = view; thus works in the single user test, but not in production.

The interfaces IWDView and IWDViewElement provide the methods required for modifying the UI elements.

·        IWDView provides a method for creating new UI elements:
IWDButton submitButton = (IWDButton) view.createElement(IWDButton.class, null);
In this case a pushbutton is created with a unique ID
or
IWDButton submitButton = (IWDButton) view.createElement(IWDButton.class, "submitButton");

·        IWDView provides a method for accessing existing UI elements using the ID:
IWDButton submitButton = (IWDButton) view.getElement("submitButton");

·        By default, a view contains a TransparentContainer UI element, whose ID is RootUIElementContainer. This element is the top UI element in the hierarchy of the UI elements of a view. This condition cannot be changed, modifications can only be defined for the UI element children of this container.

Note

Note that exactly one view is assigned to a UI element. Therefore, it is not possible to separate UI elements from multiple views or transfer them from one view to another.

  

  

 

End of Content Area