Default selection of Radio Button when added to h:panelGrid
Shemida Nivedha
Greenhorn
Joined: May 22, 2008
Posts: 18
posted
0
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
Ganesan Ramakrishnan
Ranch Hand
Joined: Mar 18, 2008
Posts: 84
posted
0
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
Joined: May 22, 2008
Posts: 18
posted
0
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 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
Joined: May 22, 2008
Posts: 18
posted
0
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
Joined: Mar 18, 2008
Posts: 84
posted
0
<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