Problematic
Sometimes you need to have an input field in read-only with F4 Help capability for several reasons:
Unfortunately, if you switch you input field to read-only, Web Dynpro does not display the F4 Help button anymore.
The goal of this article is to show you how to make this possible via public WD APIs.
Prerequisites
You have already a Web Dynpro application with a context element already bound to an input field and working at runtime.
Steps
For the sake of this example, let's define the following context:
Here is the read-only input field with the button to trigger the search help:
method onactionbrowse_class .
data lo_nd_plugin type ref to if_wd_context_node.
data ls_plugin type ags_s_plugin.
data lo_view type ref to if_wd_view.
data lr_structure type ref to data.
" Get the view
lo_view ?= wd_this->wd_get_api( ).
" Get the Plugin attribs
lo_nd_plugin = wd_context->get_child_node( name = wd_this->wdctx_plugin ).
lo_nd_plugin->get_static_attributes(
importing
static_attributes = ls_plugin ).
" Get the struct ref
get reference of ls_plugin into lr_structure.
" Call the search help
wd_this->wd_get_api( )->get_component( )->
get_window_manager( )->open_value_help(
search_term = 'Select a Plugin Class'" Search Term (Label)
view = lo_view " Web Dynpro: View Controller
event_handler = 'EVT_F4_HELP_SELECTED' " Name of Event Handler
fieldname = 'CLASS_NAME' " Field Name
structure = lr_structure " Structure
multi_select = abap_false " Multiple selection
).
endmethod.
You can notice that you pass an event name to handle the user’s selection.
The rest is self-explanatory.
When clicking on the button you should have the F4 Help pop-up appearing:
Handle the Search Help Event
method evt_f4_help_selected .
data lo_nd_plugin type ref to if_wd_context_node.
data ls_plugin type wd_this->element_plugin.
data l_parameter type wdr_event_parameter.
field-symbols <lft_table_field_vals> type any table.
field-symbols <lft_table_fields> type any table.
field-symbols <lfs_field_new_value> type any.
field-symbols <lfs_field_value> type any.
" Get the context
lo_nd_plugin_edit = wd_context->get_child_node( name = wd_this->wdctx_plugin_edit ).
lo_nd_plugin_edit->get_static_attributes(
importing
static_attributes = ls_plugin_edit ).
" Get the fields (here only ‘CLASS_NAME’ is in the list)
read table wdevent->parameters
with table key name = `EXPORT_PARAMETER_TAB`
into l_parameter.
assign l_parameter-value->* to <lft_table_fields>.
loop at <lft_table_fields> assigning field-symbol(<lfs_field>).
" Get the selection
read table wdevent->parameters
with table key name = `RESULT_TAB`
into l_parameter.
assign l_parameter-value->* to <lft_table_field_vals>.
" Get the values
loop at <lft_table_field_vals> assigning field-symbol(<lfs_table_field_val>).
" Get the field new value
assign component <lfs_field> of structure <lfs_table_field_val> to <lfs_field_new_value>.
" Get the field current value
assign component <lfs_field> of structure ls_plugin to <lfs_field_value>.
" Change value
<lfs_field_value> = <lfs_field_new_value>.
endloop.
endloop.
" Trigger changes?
if lines( <lft_table_fields> ) > 0.
" Update WD context
lo_nd_plugin->set_static_attributes(
exporting
static_attributes = ls_plugin ).
endif.
method.
This code is generic for the single value selection in the search help, for multiple values, you’ll need to adapt if.
The first list contains the field ‘CLASS_NAME’. It can be, in your structure, that you linked 2 fields together with a search help, for instance a WD Component and a WD View; when you select the view of a component, you will have 2 fields in it: one for the Component and one for the View.
The second list contains the user selection values with your structure. Here this is a single selection, then you’ll get one line.
The code within the second loop will assign each value from what the user has selected to the current WD context structure.
In the end, the WD structure is set and the selection appears in the read-only input field.
After the selection here is you read-only input field filled with the selected value:
And once you did all of this, you may wonder how to empty the input field !
If you are the owner of the search help, you can always add a blank line at the beginning, then selecting it would empty the input field.
The other option is to add a second button.
Here is the F4 help pop-up with a blank line:
Et voila, that's it!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
13 | |
10 | |
10 | |
9 | |
8 | |
7 | |
6 | |
5 | |
5 | |
5 |