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.
Provide node name RBG, enter
Right click on node RBG, create attribute.
Provide name as GENDER, type as GENDER and enter.
Step3: Insert Radio Button Group in Layout.
Go to layout, right click on ROOTUIELEMENTCONTAINER, create element, name as RBG, type as RadioButtonGroupByKey.
Step4: Create binding for radio button group.
Select RBG UI element, click on the yellow icon under properties, select GENDER attribute.
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.
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.
Step7:Go to methods, add logic.
Go to methods tab, double click on method ONACTIONON_SELECT, add below logic.
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.