Академический Документы
Профессиональный Документы
Культура Документы
LeadSelection
Anyone who starts developing an application using Web Dynpro ABAP comes
across using the leadSelection or selection of a context node somewhere within
the user interface, since many ui elements either utilize the leadSelection (e.g.
DropDownByIndex) or the selection (e.g. CheckboxGroup) or both (e.g. the Table).
This makes these two concepts (besides context binding) some of the most
important ones regarding using ui elements. Therefore for a developer the
question always arises sooner or later: What excatly is their purpose and how
should I use them in my application? Let me give you quick overview:
leadSelection
• At context node level – hence there is only a single one per node
• Denotes a single context element (e.g. table row, dropdown entry) as being
special
Selection
• At context element level – hence many of them can be selected or not
(while the minimum and maximum number of selected elements is
determined by the selectionCardinality of the node)
my_node->set_lead_selection( my_context_element ).
my_node->set_lead_selection_index( 1 ).
In contrast to Web Dynpro Java, the numbering starts with 1 – not with 0 – as this
is common in ABAP and offers some performance benefits.
There are of course methods to retrieve the index of element that holds the
leadSelection or the context element itself.
my_context_element = my_node->get_lead_selection( ).
lead_selection_index = my_node->get_lead_selection_index( ).
As the leadSelection can be used to navigate between detail data, we will create
a small example with two DropDownByIndex where the selected value of the first
one determines the available entries in the second one.
It is a demo application that is part of the transport request, which can be
downloaded at the end of this blog. It is called ZWDAA_BC_LEAD_SELECTION.
In order to achieve the desired result, create a 0..N node MAIN_VALUES with an
attribute TEXT of type STRING. Then add a 0..N sub node SECONDARY_VALUES to
MAIN_VALUES. Add an attribute TEXT of type STRING as well.
The next step is to specify a supply function to both nodes. Choose the
S_MAIN_VALUES and S_SECONDARY_VALUES as their names and copy the coding
below into them.
method s_main_values .
data:
lt_main_values type if_main=>elements_main_values,
main_values like line of lt_main_values.
do 5 times.
main_values-text = sy-index.
insert main_values into table lt_main_values.
enddo.
endmethod.
method s_secondary_values .
data:
lt_secondary_values type if_main=>elements_secondary_values,
secondary_values like line of lt_secondary_values,
parent_text type string.
endmethod.
The next step is to create the two DropDownByIndex. The first one is called
MAIN_VALUES while the second one is called SECONDARY_VALUES. Now bind their
texts attributes to the corresponding TEXT attribute in the context.
For accessibility reasons create a label pointing to the first drowndown. Mark the
first dropdown as being a label for the second one by setting its labelFor attribute.
Please create an empty action and assign it to the onSelect event of the first
dropdown. This will trigger a roundtrip whenever a user selects an entry.
Otherwise you need to create an additional button for triggering a roundtrip.
The last step is to create an application and to make sure that the window
embeds our newly created view. After starting the application you will see that
after choosing a value of the first dropdown the available entries in the second
dropdown change as well.
The demo application where you can see how it works is
ZWDAA_BC_DEP_LEAD_SEL.
Web Dynpro ABAP offers several methods to toggle the selection of a certain
context element and to determine if a user selected a particular element.
There is also the possibility to retrieve all currently selected context elements.
data:
lt_selected_elements type WDR_CONTEXT_ELEMENT_SET
lt_selected_elements = my_node->get_selected_elements( ).
In closing
This weblog provides you with a first introduction to the two concepts of selection
and leadSelection. The examples are also available as a transport request that
you can import to your system. You can download it from here.
A more advanced topic concerning the leadSelection is the usage of singleton
nodes and the selectionChangeBehaviour. Expect more details on it in another
weblog. :)