JSF Examples


select Items Tag Example
Previous Home Next

Tag Description: JSF Tag is use to add a child UISelectItems component to the UIComponent associate with the enclosing parent tag.SelectItems represents a single item in the list of supported items associated with a UISelectMany or UISelectOne component.

Code for <f:selectItems> Example:

For run this example following step is required.

Step 1 :

Welcome page of Example

   Name= welcomeJSF.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@taglib prefix="f" uri=""%>
<%@taglib prefix="h" uri=""%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

This file is an entry point for JavaServer Faces application.
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<h1><h:outputText value="Tag <f:selectItems> Example "/></h1>

<h:panelGrid columns="2" cellpadding="2" cellspacing="2">
<h:outputLabel value="Select a day from the list" />

<%-- Store object value into variable from list --%>
<h:selectOneMenu value="#{selectMenu.display}" >
<%-- Disaply List form Bean class --%>
<f:selectItems id="result" value="#{selectMenu.items}" />
<h:commandButton action="#{}" value="Submit" />

<%-- Display result --%>
<h:panelGrid rendered="#{selectMenu.flag != false}"  >
<h:outputLabel value="Object value of selected day == " >
<h:outputText value="#{selectMenu.display}" />

Step 2 :

ManagedBean class for provide logic in program

 * Save as a
package r4r.JSF2;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.model.SelectItem;

/* -- Name of Bean -- */
@ManagedBean(name = "selectMenu")
public class SelectMenuBean {

/* -- create a list -- */
private SelectItem[] items = new SelectItem[]{
//Add Object value and String value into list
new SelectItem(01, "Sunday"),
new SelectItem(02, "Monday"),
new SelectItem(03, "Tuesday"),
new SelectItem(04, "Wednesday"),
new SelectItem(05, "Thrusday"),
new SelectItem(06, "Friday"),
new SelectItem(07, "Saturday"),
private String display;
private boolean flag = false;

public String getDisplay() {
return display;

public void setDisplay(String display) {
this.display = display;

public SelectItem[] getItems() {
return items;

public void setItems(SelectItem[] items) {
this.items = items;

public boolean isFlag() {
return flag;

public void setFlag(boolean flag) {
this.flag = flag;

/* --  show method -- */
public String show() {
flag = true;
return "show";



Previous Home Next

Tolal:0 Click:

Show All Comments

Did not find what you were looking for leave your name and message. We will revert within 24 hours
Comment / Feedback: