Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

dynamically add checkboxes on webdynpro view

I have a requirement wherein i have to read a database table and based on the number of entries in this table, i have to add that many checkboxes on the webdynpro view at runtime.

Please let me know how this can be achieved.

regards,

Priyank

Former Member
replied

Here is the code


  DATA: lr_root_node TYPE REF TO if_wd_view_element,
        lr_container TYPE REF TO cl_wd_uielement_container,
        lr_context_node_info TYPE REF TO if_wd_context_node_info,
        st_contxt_attr TYPE wdr_context_attribute_info,
        lr_check_box TYPE REF TO cl_wd_checkbox.


  IF first_time = abap_true.

    CALL METHOD view->get_element
      EXPORTING
        id      = 'ROOTUIELEMENTCONTAINER'
      RECEIVING
        element = lr_root_node.

    lr_container ?= lr_root_node.

<b>Get ref of node</b>
    lr_context_node_info = wd_context->get_node_info( ).
<b>Create attributes</b>
    st_contxt_attr-name = 'A'.
    st_contxt_attr-type_name = 'WDY_BOOLEAN'.

    lr_context_node_info->add_attribute( st_contxt_attr ).

    st_contxt_attr-name = 'B'.
    st_contxt_attr-type_name = 'WDY_BOOLEAN'.

    lr_context_node_info->add_attribute( st_contxt_attr ).

    st_contxt_attr-name = 'C'.
    st_contxt_attr-type_name = 'WDY_BOOLEAN'.

    lr_context_node_info->add_attribute( st_contxt_attr ).


<b>Create checkboxes</b>

    CALL METHOD cl_wd_checkbox=>new_checkbox
      RECEIVING
        control = lr_check_box.
<b> Bind Checked mandatory parameter</b>

    lr_check_box->bind_checked( path = 'A' ). -----> this is the first attribute. In the same
                                                                          fashion you can add remaining  
                                                                          attributes

    lr_check_box->set_text( value = '1st check box').

    cl_wd_matrix_head_data=>new_matrix_head_data( element = lr_check_box ).
    lr_container->add_child( lr_check_box ).



  ENDIF.

You can keep the reference <b>lr_check_box</b> in the attributes tabs for you to later check which checkbox was checked using method GET_CHECKED of class CL_WD_CHECKBOX.

<b>No context node or attributes are required to be created. It is created dynamically as shown above. Copy the code as it is in WDDOMODIFYVIEW of the view controller.

To register the on ON_TOGGLE EVENT, in the importing parameter of the following code

CALL METHOD cl_wd_checkbox=>new_checkbox

exporting

ON_TOGGLE = 'TEST1'

RECEIVING

control = lr_check_box.

TEST1 is the action method which is required to be created in the Action tab. Then in event handler method you can write you desired code also. Do it for all the check boxes that you have added if required.

</b>

Regards,

Sridhar Karra.

Please reward points if answer is satisfactory!!!

Message was edited by:

Sridhar Karra

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question