This is used when you have to allow the user to select only one option from the list. It renders an html "select" element of any size and no "multiple" attribute. The choices that we have to display in the list are shown by f:selectItem or f:selectItems. size attribute is used to set the number of options to display at a time. If its size is not specified then it shows all the choices i.e. its default size is equal to no. of available options. If we set size attribute to less than the total no. of available choices then a scrollbar appears and the number of elements specified in the size attribute are shown. We can see other options by moving the scrollbar down and up. If size is set to "1" then drop down menu is rendered. So instead of using this strategy, its good to use "selentOneMenu" tag provided by JSF.
Code Description :
<%@ 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:selectOneListbox example</title>
<style type="text/css">
<!--
body{
background-color:#fff2f2;
margin-top:30;
}
-->
</style>
</head>
<body >
<h:form><center>
<t:selectOneListbox id="sol" size="3" title="select one option">
<f:selectItem id="si1" itemLabel="Thums Up" itemValue="11" />
<f:selectItem id="si2" itemLabel="Limca" itemValue="22" />
<f:selectItem id="si3" itemLabel="Pepsi" itemValue="33" />
<f:selectItem id="si4" itemLabel="Sprite" itemValue="44" />
<f:selectItem id="si5" itemLabel="Frooti" itemValue="55" />
<f:selectItem id="si6" itemLabel="Coca-Cola" itemValue="66" />
</t:selectOneListbox>
</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:selectOneListbox 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/selectOneListbox.jsf"
enctype="application/x-www-form-urlencoded">
<center>
<select id="_idJsp0:sol" name="_idJsp0:sol" size="3"
title="select one option">
<option value="11">Thums Up</option>
<option value="22">Limca</option>
<option value="33">Pepsi</option>
<option value="44">Sprite</option>
<option value="55">Frooti</option>
<option value="66">Coca-Cola</option>
</select>
</center>
<input type="hidden" name="_idJsp0_SUBMIT" value="1" />
<input type="hidden" name="javax.faces.ViewState"
id="javax.faces.ViewState" value="rO0ABXVyABNbTGphdmEubG
FuZy5PYmplY3Q7kM5YnxBzKWwCAAB4cAAAAAN0AAE3cHQAGy9wYWdlcy9
zZWxlY3RPbmVMaXN0Ym94LmpzcA==" /></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 selectOneListbox tag
Post your Comment