Radio button group by Key in webdynpro ABAP

Radio Button Group by Key: When ever we have fixed values for a domain, we will use this UI element to display them in the form of radio button group.

In the below example we are going to display GENDER, in the form of radio button by using radio button by key UI element.I recommend you to check GENDER domain in SE11 and understand fixed values.

Step1: Go to SE80, create a web dynpro component ZSAPN_RB_GROUP.
Step2:Create View Context.

Go to main view, go to context, right click and create a node.

Using Radio Button Group by Key in Web Dynpro ABAP

Provide node name RBG, enter

Using Radio Button Group by Key in Web Dynpro ABAP

Right click on node RBG, create attribute.

Using Radio Button Group by Key in Web Dynpro ABAP

Provide name as GENDER, type as GENDER and enter.

Using Radio Button Group by Key in Web Dynpro ABAP

Step3: Insert Radio Button Group in Layout.

Go to layout, right click on ROOTUIELEMENTCONTAINER, create element, name as RBG, type as RadioButtonGroupByKey.

Using Radio Button Group by Key in Web Dynpro ABAP

Step4: Create binding for radio button group.

Select RBG UI element, click on the yellow icon under properties, select GENDER attribute.

Using Radio Button Group by Key in Web Dynpro ABAP

Using Radio Button Group by Key in Web Dynpro ABAP

Now you can see 5 radio buttons in a group.

Step5: Go to Context and create one more attribute.

Go to view context, create one more attribute with name text, type char30.

Using Radio Button Group by Key in Web Dynpro ABAP

Go to layout, create one more UI element TextView UI element, bind text property to TEXT attribute.

Step6:Create action method for Radio Button Group, on select property.

Using Radio Button Group by Key in Web Dynpro ABAP

Step7:Go to methods, add logic.

Go to methods tab, double click on method ONACTIONON_SELECT, add below logic.

Using Radio Button Group by Key in Web Dynpro ABAP

Use Code Wizard to read node and set text attribute.

  DATA LO_ND_RBG TYPE REF TO IF_WD_CONTEXT_NODE.

  DATA LO_EL_RBG TYPE REF TO IF_WD_CONTEXT_ELEMENT.
  DATA LS_RBG TYPE WD_THIS->ELEMENT_RBG.

*   navigate from  to  via lead selection
  LO_ND_RBG = WD_CONTEXT->GET_CHILD_NODE( NAME = WD_THIS->WDCTX_RBG ).

*   @TODO handle non existant child
*   IF lo_nd_rbg IS INITIAL.
*   ENDIF.

*   get element via lead selection
  LO_EL_RBG = LO_ND_RBG->GET_ELEMENT( ).
*   @TODO handle not set lead selection
  IF LO_EL_RBG IS INITIAL.
  ENDIF.

*   get all declared attributes
  LO_EL_RBG->GET_STATIC_ATTRIBUTES(
    IMPORTING
      STATIC_ATTRIBUTES = LS_RBG ).


  DATA LO_EL_CONTEXT TYPE REF TO IF_WD_CONTEXT_ELEMENT.
  DATA LS_CONTEXT TYPE WD_THIS->ELEMENT_CONTEXT.
  DATA LV_TEXT TYPE WD_THIS->ELEMENT_CONTEXT-TEXT.

*     get element via lead selection
  LO_EL_CONTEXT = WD_CONTEXT->GET_ELEMENT( ).

*     @TODO handle not set lead selection
  IF LO_EL_CONTEXT IS INITIAL.
  ENDIF.

*     @TODO fill attribute
*     lv_text = 1.
  IF LS_RBG-GENDER = 'F'.
    LV_TEXT = 'Female Selected'.

  ELSEIF LS_RBG-GENDER = 'M'.
    LV_TEXT = 'Male Selected'.

  ELSEIF LS_RBG-GENDER = 'N'.
    LV_TEXT = 'Neutrel Selected'.
  ENDIF.

*     set single attribute
  LO_EL_CONTEXT->SET_ATTRIBUTE(
    NAME =  `TEXT`
    VALUE = LV_TEXT ).

Activate the component, create application and test.

Using Radio Button Group by Key in Web Dynpro ABAP

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值