Skip to content

Instantly share code, notes, and snippets.

@darbyluv2code
Created August 23, 2017 05:18
Show Gist options
  • Select an option

  • Save darbyluv2code/0f80e35bd1cb5a6bb88a17e550a9f6b8 to your computer and use it in GitHub Desktop.

Select an option

Save darbyluv2code/0f80e35bd1cb5a6bb88a17e550a9f6b8 to your computer and use it in GitHub Desktop.
JSF - drop-down lists
package com.luv2code.jsf.hello;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
@ManagedBean
public class StudentTwo {
private String firstName;
private String lastName;
private String country;
// list of countries for the drop-down list
List<String> countryOptions;
// no-arg constructor
public StudentTwo() {
// populate the list of countries
countryOptions = new ArrayList<>();
countryOptions.add("Brazil");
countryOptions.add("France");
countryOptions.add("Germany");
countryOptions.add("India");
countryOptions.add("Turkey");
countryOptions.add("United Kingdom");
countryOptions.add("United States");
}
// getter/setter methods
// need to add a getter method for country options
public List<String> getCountryOptions() {
return countryOptions;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment