This is the section where you will learn about "selectOneMenu" tag. This is used to display the element that enables the user to select only one among the list of available options. In the menu only one option is displayed at a time. This tag renders an html "select" element of size "1" with no multiple attribute. So have a look on the difference between listbox and menu. listbox can be specified of any size but menu is set to size "1" by default. The choices that we have to display in the list are added by f:selectItem or f:selectItems.
Code Description :
| <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%> <f:view> <html> <body> <h:form> <h:selectOneMenu id="som" value="TableBean.perInfoAll" title="select any one in this menu"> <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" /> </h:selectOneMenu> </h:form> </body> </html> </f:view> |
Rendered Output :

Html Source Code: Here you can see that size of the element is set to "1" in the html source code.
|
<html> |
This tag contains some attributes that can be used for different purposes. These attributes are summarized 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: JSF selectOneMenu Tag View All Comments
Post your Comment