Skip to Content
author's profile photo Former Member
Former Member

Retrieving ID of selected RadioButton

Does anyone know how to retrieve the ID of the selected RadioButton in a RadioButtonGroup? When i find the selected RadioButton and do call getId() I get something weird, that references the group and a random letter set. If I do a getValueAsDataType().toString() I get "true."

How do you find the ID value for the selected RadioButton....that ID that you defined in the JSP?

Thanks!

Add a comment
10|10000 characters needed characters exceeded

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Oct 19, 2005 at 04:17 PM

    Thanks, Praksh, but rb.getKey() gives me the <b>key</b> attribute value for the RadioButton. I am looking for the <b>id</b> attribute value for the RadioButton.

    Do you know how to find this?

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Alexa,

      According to the API documentation for the radioButton, the key attribute for a radioButton is:

      key

      A string which is assigned to the radioButton when the form is sent to the server. A key string must be defined and must not be empty.

      id

      Identification name of the radioButton.

      Can you set key and id to the same value? If not, are you populating the id and key attributes from a bean array? If so, you could always get the radio button id by grabbing the key and then cross referenceing (i.e. keep id at position 0 and key at position 1 in your radio button setup array).

      Hope this helps,

      Marty

  • author's profile photo Former Member
    Former Member
    Posted on Oct 19, 2005 at 03:58 PM

    I think there is bug with htmlb control radio button group. I would recommend you to use <b>key</b<> and retrieve the key by doing the following.

    <hbj:content id="myContext" >
      <hbj:page title="Template for a portal component">
       <hbj:form id="myFormId">
        <hbj:radioButtonGroup
                   id="radioGroup"
                   columnCount="2" >
    
                   <hbj:radioButton
                           id="First"
                           text="Test1"
                           key="First"
                           jsObjectNeeded="true"
                   />
    
                   <hbj:radioButton
                           id="Second"
                           text="Test2"
                           key="Second"
                           jsObjectNeeded="true"
                   />
        </hbj:radioButtonGroup>
        <br>
        <hbj:button 
    					id="SubButton" 
    					text="Submit" 
    					tooltip="Sends your info" 
    					onClick="onClick" 
    					width="30px" 
    					design="EMPHASIZED" 
    					jsObjectNeeded="true">
    				</hbj:button>
       </hbj:form>
      </hbj:page>
    </hbj:content>

    package com.ust.radio;
    
    import com.sapportals.htmlb.RadioButton;
    import com.sapportals.htmlb.RadioButtonGroup;
    import com.sapportals.htmlb.event.Event;
    import com.sapportals.htmlb.page.DynPage;
    import com.sapportals.htmlb.page.PageException;
    import com.sapportals.portal.htmlb.page.JSPDynPage;
    import com.sapportals.portal.htmlb.page.PageProcessorComponent;
    import com.sapportals.portal.prt.component.IPortalComponentResponse;
    
    
    public class display extends PageProcessorComponent {
    
    	public DynPage getPage() {
    		return new MyDynPage();
    	}
    
    	// JSPDynPage
    	public class MyDynPage extends JSPDynPage {
    		
    
    		/*
    		Used for user initialization. called when the application is started
    		*/
    		public void doInitialization() {
    			
    		}
    
    
    		/*
    		Used for handling the input. Generally called each time
    		after doInitialization
    		*/
    		public void doProcessAfterInput() throws PageException {
    			RadioButtonGroup rg =  (RadioButtonGroup) this.getComponentByName("radioGroup");
    			RadioButton rb = (RadioButton) rg.getRadioButtonForKey(rg.getSelection());
    			IPortalComponentResponse response = (IPortalComponentResponse) this.getResponse();
    			response.write(rb.getKey());
     
    		}
    
    		/*
    		Used for handling the output. This method is always called.
    		*/
    		public void doProcessBeforeOutput() throws PageException {
    			// set the name of your JSP page
    			setJspName("display.jsp");
    		}
    
    	
    		
    	}
    }

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 20, 2005 at 11:59 AM

    Good suggestion...it worked! Thank you, Marty.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 20, 2005 at 02:22 PM

    I already knew how to find the key, and the key had to be a <i>different</i> value from that for which I was looking. I needed the key value, along with a corresponding text value, so I was looking to place this value in the ID. Marty's suggestion was to keep a 2-D array, and instead of setting the key to a value from the bean, set the key of the RadioButotn to the position in the array through which I was iterating. Then, in the Java code, I grabbed this array position (through rb.getKey()) which was stored as the key and got the actual key and ID values that I was trying to set from the 2-D array stored in the bean.

    Since I am only able to retrieve the key value from a RadioButton, I could not store two unique values (as key and ID) in the RadioButton attributes. I instead had to refer back to the stored array from the bean, using the array position set as the key.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.