• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Default selection of Radio Button when added to h:panelGrid

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I am new to JSF and I am trying out some examples.
My requirement is that I have to have a screen as below.

Label1 TextBox1

Label2 o Label3 TextBox2
o Label4 Menu1

where o represents a Radio Button.

I am able to get this structure but by default no radio buttons are selected. I wanted the first label namely the Label3 to be selected by default.
Kindly provide me solution as of what needs to be done to have the default selection in the radio buttons.
Thanks in advance,
Regards,
Shemida
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

You can do it in the javascript when onload . for example
inside the onload function(){
var radioVal = document.getElementsByName('formname:selectoneradioname');

its returning array of radioVal. From this array you can select whatever you want

radioVal[0].checked=true;
or radioVal[1].checked=true;
 
Shemida Nivedha
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ganesan,
Thanks for the info.
I tried the changes you have asked me to do. Javascript is also new to me ,so could you tell me if what I have done is right or not.
As of now the radio buttons are not getting selected by default.

My jsp is

<script type="text/javascript">
function initForm() {
var radioVal = document.getElementById("addVmsHostForm:radio1");
radioVal[0].checked=true;
}
</script>
</head>

I call the initForm() in the onload of <body>.

the html regenerated code for radio button is

<tr>
<td><table border="1" id="jbpns_2fprov_2fdefault_2fotherAjaxportletWindowsnpbj:j_id_jsp_1559037212_0:AddVMSHost:addVmsHostForm:radio1" class="selectOneRadio">
<tr>
<td>
<input type="radio" name="jbpns_2fprov_2fdefault_2fotherAjaxportletWindowsnpbj:j_id_jsp_1559037212_0:AddVMSHost:addVmsHostForm:radio1" id="jbpns_2fprov_2fdefault_2fotherAjaxportletWindowsnpbj:j_id_jsp_1559037212_0:AddVMSHost:addVmsHostForm:radio1:0" value="1" /><label for="jbpns_2fprov_2fdefault_2fotherAjaxportletWindowsnpbj:j_id_jsp_1559037212_0:AddVMSHost:addVmsHostForm:radio1:0"> HostURL </label></td>
</tr>
<tr>
<td>
<input type="radio" name="jbpns_2fprov_2fdefault_2fotherAjaxportletWindowsnpbj:j_id_jsp_1559037212_0:AddVMSHost:addVmsHostForm:radio1" id="jbpns_2fprov_2fdefault_2fotherAjaxportletWindowsnpbj:j_id_jsp_1559037212_0:AddVMSHost:addVmsHostForm:radio1:1" value="2" /><label for="jbpns_2fprov_2fdefault_2fotherAjaxportletWindowsnpbj:j_id_jsp_1559037212_0:AddVMSHost:addVmsHostForm:radio1:1"> Address Name</label></td>
</tr>
</table></td>
</tr>

Can you tell me where I went wrong?
Thanks for your help.
Regards,
Shemida
 
Ganesan Ramakrishnan
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Can you show your radio button part of code in your jsp(not the rendered html code).
[ June 03, 2008: Message edited by: Ganesan Ramakrishnan ]
 
Shemida Nivedha
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am attaching the code for your reference.

<h:panelGrid columns="2">
<h:outputText styleClass="portal-font" value="Host Name" />
<h:inputText required="true" />

<h:outputText styleClass="portal-font" value="Host Address" />

<h:panelGroup>
<h:panelGrid columns="2" border="1">
<h:panelGrid columns="1">
<h:selectOneRadio disabledClass="selectOneRadio_Disabled"
styleClass="selectOneRadio" id="radio1" layout="pageDirection"
rendered="true" border="1">
<f:selectItem itemValue="1" itemLabel="HostURL " />
<f:selectItem itemValue="2" itemLabel="Address Name" />
</h:selectOneRadio>
</h:panelGrid>
<h:panelGrid columns="1" border="1">
<h:inputText required="true" />
<h:selectOneMenu id="theme"
valueChangeListener="#{VoiceMailServerDetails.valueChanged}">
<f:selectItems value="#{VoiceMailServerDetails.hostAddressMenu}" />
</h:selectOneMenu>
</h:panelGrid>
</h:panelGrid>
</h:panelGroup>

Regards,
Shemida
 
Ganesan Ramakrishnan
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Shemida,

I tried in my system, its working fine. Just give the id to <f:selectItem> and also give the proper id of <h:selectOneRadio to javascript code snippet.

Regards
Ganesan
 
Shemida Nivedha
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Could you tell as in what id needs to be given in the javascript?
As of now I have the id for selectRadioButton to be "radio1".
DO I need to give the id for each selectItem also?
If so by which id can i refer to the radioButtons from the Javascript.
Sorry I tried out many possibilities & i could not get this done.
Kindly give me the exact details as of what I must add in the javascript.
Regards,
Shemida
 
Ganesan Ramakrishnan
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<h:selectOneRadio > id is the right one , i think you too have the same one inside the javascript.
Yes you need to give the different id for each <f:selectItem > too. this is not for inside the javascript. You should give the id
for all components , its recommended one. If the result is not coming means ,You just remove the panelgroup and panelgrid tag, then try that

Regards
Ganesan
 
reply
    Bookmark Topic Watch Topic
  • New Topic