0

JSF – selectOneMenu example

This post shows sample codes that uses JSF html:selectOneMenu.

Requirements

Stuff used in this post.

  • JSF 2.2
    • javax.faces-2.2.8.jar
  • JDK 8

JSF Managed Bean

This is our managed bean annotated with @ManagedBean. The 3 important piece of codes here are:

  1. @ManagedBean
  2. Default public no-arg constructor
  3. Setter and getter methods

First Page – Request

The first page is where the drop-down boxes are displayed. Users selects one item and hits the Submit button to go to the response page.

Second Page – Response

This page displays the selected gender from the first page.

Testing

Request Page

Open the first page (request). Select Male and hit Submit.

Response Page

JSF then displays the gender code on the response page.

Karl San Gabriel

Karl San Gabriel

Java and Enterprise Technologies Expert