cancel
Showing results for 
Search instead for 
Did you mean: 

Radio button default selection

Former Member
0 Kudos

Hi Experts,

I have two radio buttons named yes and no. I need to keep no button as the default button selected

when the user logs in . Please suggest me how to do it.

Thanks a lot in advance.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Depends on if you use

- individual radio buttons

- RadioButtonGroupByKey

- RadioButtonGroupByIndex

In the first two cases, set the value of the context attribute to which the "selectedKey" property is bound to the value that selects the "no" button.

In the third case, set the lead selection of the context node to which the RadioButtonGroupByIndex is bound to the index corresponding to the "no" button.

Armin

Former Member
0 Kudos

Hi Armin,

Thanks a lot for the reply.

I am mapping the radio buttons with the value from BAPI.

Please suggest me which one will be the best option for me to choose.

I am using radio buttons for the first time in my application so i am facing this problem.

Thank you again.

former_member201361
Active Contributor
0 Kudos

Hi Srini,

if u are getting the values from BAPI , then use RadioButtonByIndex.

Create a Context node say "radio" and Attribute say "text".

Copy the Data from the Bapi to the this Context Node. and set the text property of the RadioButtonByIndex to this Context Node.

for more info, please refer this link :

[http://help.sap.com/saphelp_nwce711/helpdata/en/59/b2af840e67514f8e8973d97d494c9b/content.htm]

Thanks and Regards

Former Member
0 Kudos

Hi Armin,

Thanks a lot for the reply. Can you please elaborate on this.

I have mapped yes and no radio buttons to a single model attribute as per the BAPI.

Now what should i do ? Is it that both of them should be mapped to deifferent model attribites.

former_member197348
Active Contributor
0 Kudos

Hi Srini,

If you are populating the values from the backend, you need to use RadioButtonGroupByIndex UI Element.

Your model node should be like this:

RBNode (0...n)

-code (String) (YES,NO)

-description(String) (Yes,No)

Bind the texts property of the RBByIndex.

You can select your desired value, like

wdContext.nodeRBNode().setLeadSelection(indexoftherecord);

regards,

Siva

Former Member
0 Kudos

Hi Siva,

Two questions.

1 . Should i bind the Radio button by index to Value node or directly to the model node.

2 . In the code "wdContext.nodeRBNode().setLeadSelection(indexoftherecord);

how to calculate the indexoftherecord.

Kindly reply. Thanks a lot.

pravesh_verma
Active Contributor
0 Kudos

Hi Srini,

To get the index of record use this code:


int indexoftherecord = wdContext.current<Node_Name>Element().index();

Also for you first question:

You can use either of them. If you use the value node then you have to take care of getting and setting the data in the value node seperately and if you are directly using the model node the data in this kind of node will come automatically.

It just depends on the use ase youa re having.

I hope this helps you!

Thanks and Regards

Pravesh

former_member197348
Active Contributor
0 Kudos

Hi Srini,

Please check these

1 . Should i bind the Radio button by index to Value node or directly to the model node.

A:Directly to model node inside the Output node

2 . In the code "wdContext.nodeRBNode().setLeadSelection(indexoftherecord) how to calculate the indexoftherecord?

A: index of the record,

As you are populating two values "Yes" and "No"

Your table is like this:

index code description

0--


YES-Yes

1--


NO---No

So if you want to set No,

wdContext.nodeRBNode().setLeadSelection(0);

Regards,

Siva

Former Member
0 Kudos

Hi,

It's throwing runtime exception at the particular line of code.

java.lang.IndexOutOfBoundsException: Index: 1, Size: 0

Former Member
0 Kudos

Hi Paravesh,

It's throwing runtime exception at the particular line of code.

java.lang.IndexOutOfBoundsException: Index: 1, Size: 0

Please help.

pravesh_verma
Active Contributor
0 Kudos

Hi Srini,

Can you please check what is the node cardinality? Apart from that just let me know whether you have binded the node with the model node directly or the Vaue node?

I think the cardinality may be the reason of this error.

Thanks and Regards

Pravesh

former_member197348
Active Contributor
0 Kudos

Hi Srini,

I think you don't have data in the node. Are you setting the leadselection for Output/RBnode? You have to use that node only.

You can avoid this exception like this

if(wdContext.nodeRBNode().size()>=indexoftherecord)
{
wdContext.nodeRBNode().setLeadSelection(indexoftherecord);
}

note: call your RFC in wdDoInit() and populate values before using this code

Regards,

Siva

Former Member
0 Kudos

I am binding it in value node.

Cardinaliy is 0:n

i have tried passing 0 and -1 but still it's showing the same error.

Former Member
0 Kudos

I am mapping with value node.

cardinality 0:n

Thanks.

Former Member
0 Kudos

Thanks a lot Shiva. It worked.

But i am using value nodes and value attributes for data binding, so i am not able to see the radio buttons at runtime.

Can i achive the same thing by doing binding in model modes and model attributes.

former_member197348
Active Contributor
0 Kudos

Yes Srini,

You can do that. You need to use RadioButtonByIndex for this.

Regards,

Siva

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Srini,

try following code



wdContext.node<Node Name>().setLeadSelection(i);

where i is the attribute that you want to be defalut selected.

If you want 1st radiobutton to be default selected then use i = 0.

former_member185086
Active Contributor
0 Kudos

Hi

RadioButtonByGroup UI element ,If we supply data from SimpleType By default nothing is selected.

To make particular selection we put in wdDoInit

wdContext.currentContextElement().setTest("Yes");

But In case of populated data form BAPI(Say this is the special case )

put in wdDoInit wdContext.currentContextElement().setTest("");

will work

Note : will work for RadioButtonByGroup UI element

Best Regards

Satish Kumar

Former Member
0 Kudos

hi

i hope you have provided values in the Dic-> Simple Type . in emuneration .

you provide values and text . suppose . values is 1 and text is YES

and values is 2 text is NO .

create a attribute and then bind the type as simple type .

then

wdcontext.currentcontext.set<attrName>(2); in the init() method .

you can even search in SDN , there are many posts available with similar post

murali