SelectOneButton is used to choose a single item from a list using buttons.
Documentation<h:form>
<h:panelGrid columns="2" style="margin-bottom:10px" cellpadding="5">
<h:outputText value="Platform:" />
<p:selectOneButton value="#{selectOneView.option}">
<f:selectItem itemLabel="Xbox One" itemValue="Xbox One" />
<f:selectItem itemLabel="PS4" itemValue="PS4" />
<f:selectItem itemLabel="Wii U" itemValue="Wii U" />
</p:selectOneButton>
<p:commandButton value="Submit" update="display" icon="pi pi-check" />
<p:spacer />
<h:outputText value="Selected:" />
<h:outputText id="display" value="#{selectOneView.option}" style="font-weight: bold" />
</h:panelGrid>
</h:form>@Named
@RequestScoped
public class SelectOneView {
private String option;
private Theme theme;
private List<Theme> themes;
@Inject
private ThemeService service;
@PostConstruct
public void init() {
themes = service.getThemes();
}
public String getOption() {
return option;
}
public void setOption(String option) {
this.option = option;
}
public Theme getTheme() {
return theme;
}
public void setTheme(Theme theme) {
this.theme = theme;
}
public List<Theme> getThemes() {
return themes;
}
public void setService(ThemeService service) {
this.service = service;
}
}public class Theme {
private int id;
private String displayName;
private String name;
public Theme() {}
public Theme(int id, String displayName, String name) {
this.id = id;
this.displayName = displayName;
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getDisplayName() {
return displayName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return name;
}
}@Named
@ApplicationScoped
public class ThemeService {
private List<Theme> themes;
@PostConstruct
public void init() {
themes = new ArrayList<>();
themes.add(new Theme(0, "Nova-Light", "nova-light"));
themes.add(new Theme(1, "Nova-Dark", "nova-dark"));
themes.add(new Theme(2, "Nova-Colored", "nova-colored"));
themes.add(new Theme(3, "Luna-Blue", "luna-blue"));
themes.add(new Theme(4, "Luna-Amber", "luna-amber"));
themes.add(new Theme(5, "Luna-Green", "luna-green"));
themes.add(new Theme(6, "Luna-Pink", "luna-pink"));
themes.add(new Theme(7, "Omega", "omega"));
}
public List<Theme> getThemes() {
return themes;
}
}