You are on page 1of 12

This segment from our 266 page ABAP Web Dynpro manual is being made available as a sample of our

training manuals. Please contact David.Haynes@ERPtips.com if you have any SAP training needs, or visit www.ERPtips.com for more information.
Written by John Verbestel Published by Klee Associates, Inc.
Copyright Klee Associates, Inc., 2008

Unit 2 Web Dynpro Controllers


Unit Overview
The objective of this unit is to analyze the various controllers used within an ABAP Web Dynpro component. We discuss the standard components of controllers, such as methods, attributes, contexts, and properties. Then we introduce any specialized components for each controller type, such as actions and events. The standard methods (Hook methods) for each controller including firing sequence in typical processes are also discussed.

Controllers What Are They?


Controllers are used to handle application functionality. Various controllers exist as part of the Web Dynpro framework to handle different aspects of the flow logic and Web Dynpro component functionality. Programming within controllers is doWne via methods that refer to data stored in the context (Hierarchical Data Tree) or attributes.

Controllers are essentially ABAP classes with predefined methods, attributes and events that handle the basic functionality required based on the controller type. Examples of the standard functionalities are:

Hook methods Event handler methods for navigation and Action events Attributes for local data

Controllers can expose attributes, events, methods, and/or context elements to other components via an interface controller.

Mastering ABAP Web Dynpro ECC 6.0


SAPtips Sample ABAP Web Dynpro Controllers

Rev. 08/08/08

Unit 2 Web Dynpro Controllers

Klee Associates, Inc.

Methods, attributes, and events enabled as publicly visible must be marked as Interface Elements; this is a checkbox next to the pertinent element, which can be labeled Interface or Public.

Controller Types
The following table describes the various controller types available to a Web Dynpro component.

Component Controller

This is the parent controller for the Web Dynpro component. Only one component controller can exist, and it is visible to all other controller types of the Web Dynpro component. It handles the functionality of the entire Web Dynpro component.

View Controller

The view controller handles the flow-logic of the specific view of which it is a part. There is a single view controller for each view. A view controller is used, for example, to verify a user's input to a field on the View Layout.

Window Controller

The window controller manages the navigation between the views via plugs.

Custom Controller

The custom controller is optional and is created by the developer. It can be used to add functionality to the Component Controller. You can create multiple custom controllers for a given Component Controller.

Configuration Controller

Configuration controller is a special case of the custom controller, which allows for personalization functionality. There can only be one of these per Component Controller.

Interface Controller

The interface controller is used in conjunction with an interface view, which allows view assemblies to be presented through the generic Web Dynpro Framework and the sharing of a visual interface between components, along with context, methods, attributes, and events.

Rev. 08/08/08

Mastering ABAP Web Dynpro ECC 6.0

Klee Associates, Inc.

Unit 2 Web Dynpro Controllers

Components of a Controller
The common elements for all controllers consist of the following:

A properties tab with, at minimum, a description field and a used controller section

The used controller section declares a Shared Controller that is assigned in the Web Dynpro component Used Controller tab. Each controller within a Component Controller can declare the Usage of such a controller independently, and this is only required if the controller intends to leverage any shared capabilities of the shared controller (methods, views, etc.).

The Properties tab consists of the description and the development attributes. It also has a used components directory. If the controller needs to share data with another controller, it must be added to this list and thus declared explicitly. A controller should not directly map to a view controller as that would violate the MVC paradigm. A view controller should only be responsible for the User Interface component and not handle application logic directly.

A Context definition, defining the data hierarchy tree

This is considered the Global Data of the controller.

The Context defines the data hierarchy tree, which can be defined either directly by manually adding nodes and attributes (nodes = table [1-n] or table row [0-1], attributes = column). Each controller has its own context, which is mapped to other components contexts to bind data between them.

Mastering ABAP Web Dynpro ECC 6.0

Rev. 08/08/08

Unit 2 Web Dynpro Controllers

Klee Associates, Inc.

Attributes that define additional data objects separate of the context and are visible to all controller methods

Attributes are visible to all methods within the controller. Standard attributes are WD_CONTEXT referring to the Context Controller instance and WD_THIS referring to the Controller instance.

WD_THIS is synonymous to ME as it is used for a self-reference.

Methods that define controller functionality and are referred to as Hook methods.

The standard methods are WDDOEXIT( ) and WDDOINIT( ) for all controllers.

Methods provide programmer access to business application logic, database, etc., in addition to methods of helper classes. A developer can create additional instance methods that encapsulate the business logic necessary. The WDDOEXIT( ) method is invoked when the controller is first instantiated, and the WDDOWEXIT( ) is invoked upon the deletion of the context (Destruction). Developers should not code business logic in methods of a View container, as it violates good MVC principles.

Rev. 08/08/08

Mastering ABAP Web Dynpro ECC 6.0

Klee Associates, Inc.

Unit 2 Web Dynpro Controllers

Component Controllers
Component Controllers have the following additional features:

Events that can be used to trigger event handler methods defined in other controllers

Component Controllers have the capability of defining ABAP OO Events (as any ABAP Class) that can be triggered by a new instance method declared in the Methods tab.

Events can be defined with parameters that are not part of the context or attributes. An example is if you link the Component Controller to a Custom Controller via the used controller in the Properties tab of the Component Controller. An event can be defined in a Custom Controller, with an event handler method defined in the Component Controller.

In ABAP OO, if two or more methods subscribe to the same event (Reference SET HANDLER. FOR ), the order of execution is arbitrary and cannot be predicted.

Component Controllers also have additional Hook methods named: wddobeforenavigation( ), wddopostprocessing( ), wddoapplicationstatechange( ).

Mastering ABAP Web Dynpro ECC 6.0

Rev. 08/08/08

Unit 2 Web Dynpro Controllers

Klee Associates, Inc.

The additional hook methods are exclusive to Component Controllers, and there is only one Component Controller for a Web Dynpro component.

The method wbdobeforenavigation() is processed directly before a navigation request is processed.

The method wddopostprocessing() is invoked after all the views of the view assembly have been processed.

The method wddoapplicationstatechanged() is invoked when specialized window navigation plugs are triggered. This is used when navigating between windows (view assemblies) of one Web Dynpro component to another. In this situation, the current Web Dynpro component goes into Suspended mode until it is resumed via a call-back URL by the called application.

Custom Controllers
Custom Controllers are identical in form to Component Controller; the only differences are:

There can be any number of Custom Controllers defined in a single Web Dynpro component.

Custom Controllers contain only the two standard attributes and the two standard hook methods.

Additional instance methods, events, attributes, and used components can be defined. These are all considered to be Instance in that they require the controller to be instantiated. All methods, events, and attributes are considered private by default, and to expose these elements, you must set the Interface flag.

Custom Controllers are mainly used for managing business logic, thus separating them from View, Window, and Component Controllers that have specific responsibilities in the Web Dynpro framework.

Rev. 08/08/08

Mastering ABAP Web Dynpro ECC 6.0

Klee Associates, Inc.

Unit 2 Web Dynpro Controllers

Window Controllers
Window Controllers have the following additional features to the standard controller interfaces:

The Properties tab has an area to assign window help text and a help link for standardized navigation to help (similar in nature to the System Help function).

Additional attribute for the Component controller instance (WD_COMP_CONTROLLER).

Inbound and outbound plugs for cross component (Window-Window) navigation or exiting the Web Dynpro application (Exit).

For this to occur, the plugs must be set with the Interface flag enabled and the plug type defined (exit, suspend, resume). This is discussed in detail later in the course.

Window tab containing the view assembly for the views that can be displayed

View Assembly in Window Controller


The Window view assembly contains all the views that have been embedded in the window. You can define navigation on the page statically by dragging and dropping the view controllers outbound plugs to the respective inbound plugs.

Mastering ABAP Web Dynpro ECC 6.0

Rev. 08/08/08

Unit 2 Web Dynpro Controllers

Klee Associates, Inc.

View Controllers
View Controllers have the following additional parts:

Layout tab that define the User Interface for displaying data and controlling user interactive elements

Inbound and outbound plugs for navigation between view controllers (View<>View)

Inbound navigation plugs are linked to a handler method HANDLE<inbound plug>(). When navigation connections are established in the window between views, the method will fire the relevant outbound plug. This can be seen by viewing the ABAP code within the method Handle<inbound_plug>.

Action tab, linking client-side events

Example, the OnAction Property of push button is assigned an action DoThis, which results in the creation of an event handler method OnActionDoThis()

Additional Attribute for the component controller instance (WD_COMP_CONTROLLER)

By using the attribute WD_COMP_CONTROLLER, the methods of the component controller are available within the View Controller instance methods.

Two additional Hook methods wddobeforeaction() and wddomodifyview()

Method wddobeforeaction( ) is invoked if an action is triggered by any view by a client-side event. If more than one view is being presented to the client, then the wddobeforeaction() method of each presented view is invoked (sequence arbitrary) before the first onAction<actionname>() action handler method is invoked.

Method wddomodifyview() is used to dynamically manipulate the layout. This will be discussed in the programming section of the course.

Rev. 08/08/08

Mastering ABAP Web Dynpro ECC 6.0

Klee Associates, Inc.

Unit 2 Web Dynpro Controllers

View Layout Tab


The Layout consists of the Toolbar, Layout Design Area (wysiwyg), UI Element container of used UI elements, and Properties for each UI element.

The selected UI element is pulled from the UI Element List and dropped into the Design Area. The properties are then adjusted in the Properties window. Depending on the UI element chosen, a script may trigger to supply additional information. The UI element properties for elementary and complex elements will be discussed in the User Interface section of the course.

Mastering ABAP Web Dynpro ECC 6.0

Rev. 08/08/08

Unit 2 Web Dynpro Controllers

Klee Associates, Inc.

Basics of Navigation
The UI Element of type Button contains the property OnAction. The action assigned <action>, which is created using the Create icon next to the property, is tied to an action handler method onaction<action> (automatically created and placed as an entry under the Action tab). The method for the action contains generated coding to trigger the outbound plug.

For example, wd_this->Fire_to_<plugname>Plug is placed automatically in the method.

10

Rev. 08/08/08

Mastering ABAP Web Dynpro ECC 6.0

Klee Associates, Inc.

Unit 2 Web Dynpro Controllers

Lifetime of a Controller Instance


The following table describes the lifetime of the various controller instances in memory:

Component Controller

As Web Dynpro is stateful technology, the lifetime of the component controller equates to the lifetime of the Web Dynpro component. It is tied directly to the Web Dynpro runtime and is instantiated when the service is initiated.

View Controller

The view controller is instantiated when the view is first called into action. In the view properties, you can set the lifetime to be tied to the Component Controller (Framework Controlled) or only when it is visible. In the when visible case, the view controller is released when the view is no longer part of the view assembly in the window.

Window Controller

Window controllers are instantiated when they are called into action by the Web Dynpro framework. Their lifetime is controlled by the Web Dynpro framework.

Custom Controller

Custom Controllers are also managed by the Web Dynpro framework, and they are instantiated once called into action. Their lifetime is controlled by the Web Dynpro framework.

Configuration Controller

The configuration controller is tied directly to the lifetime of the Component Controller.

Mastering ABAP Web Dynpro ECC 6.0

Rev. 08/08/08

11

Unit 2 Web Dynpro Controllers

Klee Associates, Inc.

Legal Speak:

Purchase of this book or acquisition at an ERPtips class, constitutes an implied agreement by the purchaser to a limited, license granted to the purchaser by Klee Associates, Inc., specifically for purposes limited to improving your personal knowledge of SAP software which does not in any way compete with Klee Associates. This manual is protected by copyright law, and is sold or is part of an ERPtips class with the following conditions: The manual will be used for your personal professional development. The manual will not be physically copied for distribution to other individuals or converted to an electronic copy for distribution to other individuals, unless copyright permissions for copying have been acquired from Klee Associates, Inc. The manual will not be used to conduct training classes by you or other individuals, without the written permission of Klee Associates, Inc. Inclusion of the concepts in this book in any internal client training material is allowed if the source of the concepts is acknowledged as follows:

Copyright 2008 All rights reserved. Used with permission. Klee Associates, Inc.

NO WARRANTY: This documentation is delivered as is, and Klee Associates makes no warranty as to its accuracy or use. Any use of this documentation is at the risk of the user. Although we make every good faith effort to ensure accuracy, this document may include technical or other inaccuracies or typographical errors. Klee Associates reserves the right to make changes without prior notice. ERPtips is a valued resource for thousands of clients and consultants worldwide. Visit our web site for more information about upcoming training, books, and newsletters. www.ERPtips.com

ERPtips is a registered trademark of Klee Associates, Inc. No Affiliation: Klee Associates, Inc. and this publication are not affiliated with or endorsed by SAP AG. SAP AG software referred to on this site is furnished under license agreements between SAP AG and its customers and can be used only within the terms of such agreements. SAP AG is a registered trademark of SAP AG. All other product names used herein are trademarks or registered trademarks of their respective owners.
12 Rev. 08/08/08 Mastering ABAP Web Dynpro ECC 6.0

You might also like