cancel
Showing results for 
Search instead for 
Did you mean: 

Code to creating Radio Button

Former Member
0 Kudos

Hi All,

We are trying to create Radio Button UI Element dynamically.

IWDTransparentContainer container = (IWDTransparentContainer) view.getElement( "RootUIElementContainer");

IWDRadioButton radiobutton = (IWDRadioButton)view.createElement(IWDRadioButton.class, "MyRadioButton");

container.addChild(radiobutton);

This is the code we are using. We have craeted 2 context attributes and set the KeyToSelect and SelectedKey properties to it.

radiobutton.setKeyToSelect("radiooptions.male");

radiobutton.setSelectedKey("radiooptions.common");

Now for setting teh default radio button we gave this,

wdContext.currentRadiooptionsElement().setMale(1);

wdContext.currentRadiooptionsElement().setCommon(1);

But its giving an error:

com.sap.tc.webdynpro.progmodel.context.ContextException: Path null does not point to an attribute, but to com.sap.tc.webdynpro.progmodel.generation.DelegatingView@e6846b

And if we dont give the context and just create a radio button, the radio button comes as greyed out, even the text that we set is coming greyed out.

Please help me out with this...

Regards,

Becky.

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi u can put this method in the component controller.

Call this method in wdinit() of the view.

public void populateValues( )
  {
    //@@begin populateValues()
    try
    {
    	
		/*****POPULATING RADIO BUTTON**********/
		
		IWDAttributeInfo a2=wdContext.getNodeInfo().getAttribute(IPublicNewTestComp.IContextElement.RADIO);
		ISimpleTypeModifiable stm2=a2.getModifiableSimpleType();
		IModifiableSimpleValueSet svs2=stm2.getSVServices().getModifiableSimpleValueSet();
    	
		svs2.put("A","First");
		svs2.put("B","Second");
		
		/**************************************/
    }
    catch(Exception e)
    {
    	msgMngr.reportException("In populateValues "+e,false);
    }
    //@@end
  }

Former Member
0 Kudos

Can you give more details on the use-case? Why do you need to create radio buttons by code?

Maybe you can just use a radio button group defined at designtime?

Armin

Former Member
0 Kudos

Hi ,

u need to bind ur UI element to context attribute whatever u have created for ur radio button .

Former Member
0 Kudos

Hi Ami n Anup,

Can you tell me how to bind the UI element to the context, i mean the code for it??

Thanks.

former_member192434
Active Contributor
0 Kudos

Hi

I think this problem is ocurr becouse you missed some bindings of your UI element or the context mappings. Check for the same. Or try to delete that dropdownbyindex element and test application. Then insert new dropdown element once again, bind all required properties and then test.

Thanks