You are on page 1of 9

Mostrar y ocultar botones WEB Dynpro

Generar nuestro componente Web Dynpro

Despus vamos a crear un elemento tipo botn y le agregaremos la accin BOTON1


Despus vamos a crear un elemento tipo botn y le agregaremos la accin BOTON2
En la pestaa 'Diseo' de la vista principal. Vincule los atributos del nodo con las propiedades
visibles de Button1 y Button2.

En el componente COMPONENTCONTROLLER crearemos el nodo BOTONES con los atributos botn


1 y botn 2. En el tipo de los botones asignar el siguiente valor WDUI_VISIBILITY.
Posteriormente en la vita main en la pestaa contexto arrastrar el nodo Botones

Dentro del mtodo WDDOINIT agregar el siguiente cdigo

method WDDOINIT.

data lo_nd_boton type ref to if_wd_context_node.


data lo_el_boton type ref to if_wd_context_element.
data ls_boton type wd_this->element_botones.
data: lv_boton1 like ls_boton-boton1,
lv_boton2 like ls_boton-boton2.

* navigate from <context> to <button> via lead selection


lo_nd_boton = wd_context->get_child_node( name = wd_this-
>wdctx_botones ).

* get element via lead selection


lo_el_boton = lo_nd_boton->get_element( ).

lv_boton1 = 2.
lv_boton2 = 2.

lo_el_boton->set_attribute(
exporting
name = 'BOTON1'
value = lv_boton1 ).

lo_el_boton->set_attribute(
exporting
name = 'BOTON2'
value = lv_boton2 ).
endmethod.

Dentro de la accin del botn 1 poner el siguiente cdigo

method ONACTIONBOTON1.

DATA lo_nd_boton TYPE REF TO if_wd_context_node.


DATA lo_el_boton TYPE REF TO if_wd_context_element.
DATA ls_boton TYPE wd_this->element_botones.

DATA: lv_boton1 LIKE ls_boton-boton1,


lv_boton2 LIKE ls_boton-boton2.

* navigate from <CONTEXT> to <BUTTON> via lead selection


lo_nd_boton = wd_context->get_child_node( name = wd_this-
>wdctx_botones ).

* get element via lead selection


lo_el_boton = lo_nd_boton->get_element( ).

* get single attribute


lo_el_boton->get_attribute(
EXPORTING
name = 'BOTON1'
IMPORTING
value = lv_boton1 ).

lo_el_boton->get_attribute(
EXPORTING
name = 'BOTON2'
IMPORTING
value = lv_boton2 ).

IF lv_boton1 = 2.
lv_boton1 = 1.
lv_boton2 = 2.
ENDIF.

lo_el_boton->set_attribute(
EXPORTING
name = 'BOTON1'
value = lv_boton1 ).

lo_el_boton->set_attribute(
EXPORTING
name = 'BOTON2'
value = lv_boton2 ).

endmethod.
Dentro de la accin del botn 2 poner el siguiente cdigo

method ONACTIONBOTON2.

DATA lo_nd_boton TYPE REF TO if_wd_context_node.


DATA lo_el_boton TYPE REF TO if_wd_context_element.
DATA ls_boton TYPE wd_this->element_botones.

DATA: lv_boton1 LIKE ls_boton-boton1,


lv_boton2 LIKE ls_boton-boton2.

* navigate from <CONTEXT> to <BUTTON> via lead selection


lo_nd_boton = wd_context->get_child_node( name = wd_this-
>wdctx_botones ).

* get element via lead selection


lo_el_boton = lo_nd_boton->get_element( ).

* get single attribute


lo_el_boton->get_attribute(
EXPORTING
name = 'BOTON1'
IMPORTING
value = lv_boton1 ).
lo_el_boton->get_attribute(
EXPORTING
name = 'BOTON2'
IMPORTING
value = lv_boton2 ).

IF lv_boton2 = 2.
lv_boton2 = 1.
lv_boton1 = 2.
ENDIF.

lo_el_boton->set_attribute(
EXPORTING
name = 'BOTON1'
value = lv_boton1 ).

lo_el_boton->set_attribute(
EXPORTING
name = 'BOTON2'
value = lv_boton2 ).

endmethod.

Guardar, activar y generar la aplicacin web dynpro

You might also like