04 web dynpro for abap-context at design time
DESCRIPTION
04 Web Dynpro for ABAP-Context at Design TimeTRANSCRIPT
© IBM Corporation 2013
IBM Global Business Services
Web Dynpro for ABAPThe Context at Design Time
IBM Global Business Services
© IBM Corporation 2013Topic Title | Jan-2007 2
Session Overview
At design time, the developer can statically define the context structure of any controller.
Context elements have to be added to the structure hierarchy and properties have to be set for each context element.
At runtime, these properties rule the memory allocation, for example, the type of the content and the dimension of data arrays to be stored. Thus it is essential to understand the static definitions and the runtime properties related to the context .
This lesson gives a basic introduction to the context.
IBM Global Business Services
© IBM Corporation 2013Topic Title | Jan-2007 3
Learning Objectives
After completing this lesson, you will be able to: Define nodes and attributes in a controller's context
Explain how the node property's cardinality and singleton influence the memory allocation at runtime
Define the Supply function methods for populating the context at runtime.
IBM Global Business Services
© IBM Corporation 2013Topic Title | Jan-2007 4
Defining the Context Structure
Every Web Dynpro controller has exactly one hierarchical data storage structure, known as context.
The data held in the context exists only for the life span of the controller.
Once the controller instance has been terminated, all data held within its context is lost.
The structure (that is, the meta data) of a context will typically be defined at design time. However, at runtime, it is possible not only to modify the contents of the context, but also to modify its structure itself.
IBM Global Business Services
© IBM Corporation 2013Topic Title | Jan-2007 5
Context Node and Attributes
Context Node Arranged hierarchically
Permitted to have children(Nodes and Attributes)
Metadata Description declared manually or derived from DDIC structure
Context AttributeStores runtime data or references to runtime data
Based on DDIC types
Root Context Node
Context Node Properties
Context Node attributes
Context Node
IBM Global Business Services
© IBM Corporation 2013Topic Title | Jan-2007 6
Context Element Properties : Structure at Design Time
All context nodes are collections
A node collection is composed of elements
An element is an aggregation of node’s immediate children (attributes and/or nodes)
The cardinality controls the number of elements that may be held by a node collection at runtime.
IBM Global Business Services
© IBM Corporation 2013Topic Title | Jan-2007 7
Context Element Properties : Basic rules
No mapping can be defined for the root node CONTEXT
For each context you can create either attributes or nodes beneath the root node.
No mapping can be defined for individual attributes
All nodes must have a unique name within a context
All child elements within a node must have a unique name
Names of context elements may contain letters and numbers, but no special characters
IBM Global Business Services
© IBM Corporation 2013Topic Title | Jan-2007 8
Cardinality of a Context Node
Every context node has a property called cardinality.
This property is composed of two values that, taken together, describe the maximum and minimum number of elements the node collection may hold at runtime
IBM Global Business Services
© IBM Corporation 2013Topic Title | Jan-2007 9
Cardinality of a Context Node : Possible cardinality values
There are four possible cardinality values (specified as <Min>..<Max>) :
1…1 : Only one element is instantiated.
0…1 : At runtime, no more than one element is instantiated, but it is also possible that no
element is instantiated.
1…n : n elements can be instantiated, but at least one element must be instantiated.
0…n The number of instantiated elements of the context node can vary
IBM Global Business Services
© IBM Corporation 2013Topic Title | Jan-2007 10
Lead Selection Property
At runtime, exactly one of the element instances of a node can be accessed using a 1-based index value.
The lead selection of a context node points to either a single selected node element (value of the lead selection = number of the selected node element) or, if no element is selected, it has the value of the constant :
IF_WD_CONTEXT_NODE=>NO_SELECTION.
IBM Global Business Services
© IBM Corporation 2013Topic Title | Jan-2007 11
Lead Selection Property (Contd.)
The lead selection can be set automatically by the Web Dynpro framework if the context node property Initialize Lead Selection is set to true. In this case, the first element in a collection will automatically be marked as the element at lead selection.
The lead selection can also be set by program source code
Following two methods are available for this:
IF_WD_CONTEXT_NODE interface: SET_LEAD_SELECTION and SET_LEAD_SELECTION_INDEX
Default: „Yes“ (lead selection automatic, and set to the first element of a node)
Initialize Lead Selection
IBM Global Business Services
© IBM Corporation 2013Topic Title | Jan-2007 12
The Singleton Property
The Boolean property Singleton critically affects the relationship between a dependent node and its parent node.
For each instance of child node is related to the respective element in the parent node collection.
Notice that the arrows pointing to each of the child node collections originate from each element in the parent node.
Therefore, if there are n elements in the parent node, then there will be n distinct instances of a non-singleton child node.
IBM Global Business Services
© IBM Corporation 2013Topic Title | Jan-2007 13
The Singleton Property (Contd.)
If the node child node has its Singleton property set to true (which is the default), it does not matter how many elements are present in the parent node collection There will only ever be one instance of the child node
Singleton Property
IBM Global Business Services
© IBM Corporation 2013Topic Title | Jan-2007 14
The Singleton Property (Contd.)
Web Dynpro follows the principle of lazy data instantiation.
It means that unless the program actually needs to look at the data in a child node, the child node will remain unprocessed. Hence, there is no need to hold multiple instances of data the user has not requested.
The creation of a collection of the dependent node is delayed to the point when the related element of the parent collection gets the lead selection.
IBM Global Business Services
© IBM Corporation 2013Topic Title | Jan-2007 15
Supply function
Supply functions are a mechanism to repopulate child nodes
They can be assigned to each context node of a controller and is especially useful in combination with singleton nodes.
If the lead selection is changed by the user, the supply function can access the new lead selection element and recalculate the values of the child node elements accordingly.
They are called automatically at runtime by the Web Dynpro Framework in the following conditions
The node collection is initial.
The lead selection in the parent node collection is changed.
The node collection is invalidated programmatically.
IBM Global Business Services
© IBM Corporation 2013Topic Title | Jan-2007 16
Repopulating a Dependent Singleton Node: Supply Function
Supply Function
IBM Global Business Services
© IBM Corporation 2013Topic Title | Jan-2007 17
Session Summary
You should now be able to:
Define nodes and attributes in a controller's context
Explain how the node property's cardinality and singleton influence the memory allocation at runtime
How to use Supply function method for population context.