How to create a Tray dynamically
I have tried to develop a method where I can create a tray dynamically. I have embedded this code in the method WDDOINIT of my View called 'MAIN_VIEW'. My longer term plan is to create x number of trays where x is dictated by the number of entires in an Internal Table.
The code I have written compiles, but nothing appears where I thought it would. Can anyone spot what I have so fundementally missed?
Assistance is sincerely appreciated.
create object wd_this->all_in_one_util.
data: node_input type REF TO if_wd_context_node,
elem_input TYPE REF TO if_wd_context_element,
stru_input type if_main_view=>element_input.
data: lr_view type ref to cl_wdr_view,
lr_tray type REF TO CL_WD_TRAY,
tray_id type string,
lr_caption type ref to cl_wd_caption,
caption_id type string,
lr_grid_data type ref to cl_wd_grid_data,
lr_grid_layout type ref to cl_wd_grid_layout.
*Navigate from <CONTEXT> to <INPUT> via lead selection
node_input = wd_context->get_child_node( name = if_main_view=>wdctx_input ).
lr_tray = cl_wd_tray=>new_tray(
EXPANDED = ABAP_TRUE
ID = tray_id
VIEW = lr_view "'MAIN_VIEW'
WIDTH = '100%'
set the caption of the tray
concatenate lr_tray->id '_HEADER' into caption_id.
lr_caption = cl_wd_caption=>new_caption(
id = caption_id
text = 'text goes here'
view = lr_view ).
lr_tray->set_header( lr_caption ).
create the grid layout data for tray
lr_grid_data = cl_wd_grid_data=>new_grid_data( lr_tray ).
assign the layout data to the tray
lr_tray->set_layout_data( lr_grid_data ).
create a new grid layout for the content of the tray
lr_grid_layout = cl_wd_grid_layout=>new_grid_layout( lr_tray ).
assign the grid layout to the tray
lr_tray->set_layout( lr_grid_layout ).
Prashanth B Kumar replied
If we have to do any dynamic programming in webdynpro( creating UIelements dynamically ), WDDOMODIFYVIEW is the method where we need to code the logic for creating the tray.
But you have done the coding of creating tray in WDDOINIT thats why it is not working fine. Just the have the same code in WDDODMODIFYVIEW and you need to have below code to add this tray to view's ROOTUICONTAINER.
data: lr_container TYPE REF TO cl_wd_uielement_container.
lr_container ?= view->get_element( 'ROOTUIELEMENTCONTAINER' ).
" View is import parameter of wddomodifyview method.
lr_container->add_child( '' pass the tray that is created ' ).
This is the way to create dynamic UIelements in webdynpro using wddodmodifyview
For more information on dynamic programming have at following information
Prashanth Kumar B