on 10-19-2005 4:33 PM
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!
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Good suggestion...it worked! Thank you, Marty.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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");
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
89 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.