Auto Align UI Elements Dynamically in Web Dynpro ABAP
This document helps how to Auto align UI elements if there are any hidden UI elements in Web Dynpro ABAP.
Here I will demonstrate a simple scenario to hide some UI elements for a particular user and then Reorder the alignment of UI elements.
Step by Step Process
Step 1: Create a Web Dynpro Component.
Go to the SE80 transaction and create a Web Dynpro Component.
Enter Description and click on OK.
Step 2: Data Binding
Go to the Context tab of Main View and create a node MATERIAL.
Enter dictionary structure MARA and click on ‘Add attributes from structure’.
Select the required fields and click on OK.
Step 3: Layout Design.
Now Go to Layout tab, and click on Web Dynpro Code Wizard( magic symbol button).
Double click on Form to create the input UI elements in Transparent container and bind them.
Click on context and select the MATERIAL Node.
Click on Continue.
Now we can see the all the input UI elements and labels are created automatically in a transparent container. Delete the unnecessary TEXT_VIEW UI element.
Now align the UI elements in the transparent container and select the label ERSDA_LBL, under properties click on bind button for Visible property.
Select the required attribute( ERSDA ), And select the radio button ‘Bind to the property of selected Attribute’ and select ‘Visible’ property. click on OK.
Similarly, select input field ERSDA, under properties click on bind button for Visible property. Bind it to same attribute( ERSDA ), And select the radio button ‘Bind to the property of selected Attribute’ and select ‘Visible’ property. click on OK.
Now goto Methods tab, and enter below code in WDDOINIT method.
|METHOD wddoinit .
DATA lo_nd_material TYPE REF TO if_wd_context_node.
lo_nd_material = wd_context->get_child_node( name = wd_this->wdctx_material ).
lo_el_material = lo_nd_material->get_element( ).
IF sy–uname = ‘KIRAN_V’.
Now Save and Activate the Web Dynpro Component.
Create Web Dynpro Application and save it.
Enter description and save it.
Now right click on web dynpro application and click on Test.
Now you can see the output in browser with all the UI elements visible and neatly aligned for other users.
Suppose if the user ‘KIRAN_V’ ( to whom the ‘Created on’ UI has to be hidden) is logged on and execute the application, we can see the UI element ‘Created On’ is hidded and there is an empty gap in the layout which doesn’t make it look good!
Write the below code in WDDOMODIFYVIEW method.
|METHOD wddomodifyview .
DATA: lr_container TYPE REF TO cl_wd_transparent_container,
FIELD-SYMBOLS: <lr_uielement> TYPE REF TO cl_wd_uielement.
* Get the Transparent Container
LOOP AT lt_child ASSIGNING <lr_uielement>.
* Get the New Visible UI elements in the Transparent container
* Align the Layout without empty spaces of hidden UI elements
Save and activate the component and test the application.
Now we can see that the UI elements are aligned in a proper order without the empty spaces left by Hidden UI elements.
This can be used according to yourrequirements by changing the total number of columns. Note that the above generic solution works for one time hidden UI elements scenario such as – Hide UI elements for particular user or based on some values. But not for hiding and showing UI elements(again) based on actions. In such cases, you have to add the child to the transparent container back dynamically in the corresponding action handler method.