Share on Google+Share on Google+

JSF selectItems Tag

This tag is used to add a set of items to the nearest enclosing parent (select one or select many) component.

JSF selectItems Tag


This tag is used to add a set of items to the nearest enclosing parent (select one or select many) component. This tag can be used to get the list of choices from the list of objects from backing bean. So instead of writing  many selectItem tag for choices, you can use selectItems tag to get the options list in the form of list of objects from backing bean.

Code Description :

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

<h:outputText value="Select choices given below :"/><br><br>
<h:selectManyListbox id="subscriptions" value="#{SItemsBean.options}" size="3">
<f:selectItems value="#{SItemsBean.options}" />

Backing Bean ( : In the code below, we have taken array list of SelectItem objects. It has 5 constructors. One of its constructor accepts value as Object and label as String parameter while the another one  accepts value as Object, label as String, description as String  disabled as boolean parameters. description  parameter is used for own purpose to describe something and disabled is used to make the option enabled or disabled by setting it "true" and "false" respectively. You can use them according to the need. You can understand it better by the code given below :

import javax.faces.model.SelectItem;
import java.util.*;

public class SItemsBean
  private List options;
  public SItemsBean() 
  options = new ArrayList();
  SelectItem option = new SelectItem("ch1", "choice1", "This bean is for selectItems tag", true);
  option = new SelectItem("ch2", "choice2");
  option = new SelectItem("ch3", "choice3");
  option = new SelectItem("ch4", "choice4");
  option = new SelectItem("ch5", "choice5);

   public void setOptions(List opt)
   options = opt;

   public List getOptions()
   return options;

Rendered Output :

Html Source Code :

<form id="_id0" method="post" action="/coretag/pages/selectItems.jsf" enctype="application/x-www-form-urlencoded">
Select choices given below :<br><br>
<select id="_id0:subscriptions" name="_id0:subscriptions" multiple size="3"> <option value="ch1" disabled="disabled">choice1</option>
<option value="ch2">choice2</option>
<option value="ch3">choice3</option>
<option value="ch4">choice4</option>
<option value="ch5">choice5</option>

<input type="hidden" name="_id0" value="_id0" /></form>

This tag contains some attributes :

id : This is used to uniquely identify the table component. This must be unique within the closest parent component.
binding : It is a value binding expression that is used to link component to a property in a backing bean.
value : This is the value binding expression that indicates to the list or array of  selectItem instances which contains the information about the option.


Posted on: June 15, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: JSF selectItems Tag   View All Comments

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
July 12, 2012
thnx you!!!!!!!!!!!!!!

thank you very much!!!!! i love you!!! ;)