This tag is used to create radio buttons on the page. It renders html input tag with type "radio". It contains all the features of standard jsf radio component. It's layout attribute can take different values for layout of radio buttons. If this is set to "spread" value then it doesn't display html but provides feature to display radio buttons according to the developer's need. For this radio tag is used. This feature has been exposed in the example below in this tutorial.
Code Description : In this code, the index attribute is to identify the item to select for display.
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
<f:view>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title>t:selectOneRadio example</title>
<style type="text/css">
<!--
body{
background-color:#fff2f2;
margin-top:30;
}
-->
</style>
</head>
<body >
<h:form><center>
<t:selectOneRadio id="sor" value="SI" layout="spread" border="1"
style="font-weight:bold; background-color:#99CCFF;">
<f:selectItem id="si1" itemLabel="Samsung" itemValue="sa" />
<f:selectItem id="si2" itemLabel="Link" itemValue="lo" />
<f:selectItem id="si3" itemLabel="Logitech" itemValue="lg" />
<f:selectItem id="si4" itemLabel="BenQ" itemValue="bq" />
</t:selectOneRadio>
<t:panelGrid columns="2" dir="ltr" width="40%" style="color:green;" >
<t:radio for="sor" index="0"></t:radio>
<t:radio for="sor" index="1"></t:radio>
</t:panelGrid>
<hr>
<t:panelGrid columns="2" dir="ltr" width="40%" style="color:green;" >
<t:radio for="sor" index="2"></t:radio>
<t:radio for="sor" index="3"></t:radio>
</t:panelGrid>
</center></h:form>
</body>
</html>
</f:view>
Rendered Output :

Html Source Code :
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title>t:selectOneRadio example</title>
<style type="text/css">
<!--
body{
background-color:#fff2f2;
margin-top:30;
}
-->
</style>
</head>
<body >
<form id="_idJsp0" name="_idJsp0" method="post"
action="/tomahawk_tags/pages/selectOneRadio.jsf"
enctype="application/x-www-form-urlencoded"><center>
<table width="40%" dir="ltr" style="color:green;">
<tbody><tr><td><label>
<input type="radio" name="_idJsp0:sor" value="sa"
style="font-weight:bold; background-color:#99CCFF;" />
 Samsung</label></td><td><label><input type="radio"
name="_idJsp0:sor" value="lo" style="font-weight:bold;
background-color:#99CCFF;" /> Link
</label></td></tr></tbody>
</table>
<hr>
<table width="40%" dir="ltr" style="color:green;">
<tbody><tr><td><label>
<input type="radio" name="_idJsp0:sor" value="lg"
style="font-weight:bold; background-color:#99CCFF;" />
 Logitech</label></td><td><label>
<input type="radio" name="_idJsp0:sor" value="bq"
style="font-weight:bold; background-color:#99CCFF;" />
 BenQ
</label></td></tr></tbody></table>
</center><input type="hidden" name="_idJsp0_SUBMIT" value="1" />
<input type="hidden" name="javax.faces.ViewState"
id="javax.faces.ViewState" value="rO0ABXVyABNbTGphdmEubGFuZy5PYm
plY3Q7kM5YnxBzKWwCAAB4cAAAAAN0AAEzcHQAGS9wYWdlcy9zZWxlY3RPbmVSYW
Rpby5qc3A=" /></form>
<!-- MYFACES JAVASCRIPT -->
</body> </html> |
This tag contains attributes given below :
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Tomahawk selectOneRadio tag View All Comments
Post your Comment