Primefaces单选按钮,复选框示例

时间:2020-02-23 14:41:39  来源:igfitidea点击:

Primefaces单选按钮和复选框是选择元素。
以下是用于不同类型的单选按钮和复选框实现的primefaces组件。

  • SelectBooleanButton
  • SelectBooleanCheckbox
  • SelectCheckboxMenu
  • SelectManyButton
  • SelectManyCheckbox
  • SelectManyMenu
  • SelectOneButton
  • SelectOneListbox
  • SelectOneMenu
  • SelectOneRadio

让我们深入研究这些组件,看看如何在您的应用程序中利用它们。

SelectBooleanButton基本信息

SelectBooleanButton用于通过切换按钮选择二进制决策。

TagSelectBooleanButton
Component Classorg.primefaces.component.selectbooleanbutton.SelectBooleanButton
Component Typeorg.primefaces.component.SelectBooleanButton
Component Familyorg.primefaces.component
Renderer Typeorg.primefaces.component.SelectBooleanButtonRenderer
Renderer Classorg.primefaces.component.selectbooleanbutton.SelectBooleanButtonRenderer

SelectBooleanButton属性

NameDefaultTypeDescription
idnullStringUnique identifier of the component
renderedtrueBooleanBoolean value to specify the rendering of the component, when set to false component will not be rendered.
bindingnullObjectAn el expression that maps to a server side UIComponent instance in a backing bean
valuenullObjectValue of the component referring to a List.
converternullConverter/StringAn el expression or a literal text that defines a converter for the component. When it’s an EL expression, it’s resolved to a converter instance. In case it’s a static text, it must refer to a converter id
immediatefalseBooleanWhen set true, process validations logic is executed at apply request values phase for this component.
requiredfalseBooleanMarks component as required
validatornullMethod ExprA method expression that refers to a method validationg the input
valueChangeListenernullMethod ExprA method expression that refers to a method for handling a valuechangeevent
requiredMessagenullStringMessage to be displayed when required field validation fails.
converterMessagenullStringMessage to be displayed when conversion fails.
validatorMessagenullStringMessage to be displayed when validation fields.
widgetVarnullStringName of the client side widget.
disabledfalseBooleanDisables the component.
labelnullStringUser presentable name.
onchangenullStringCallback to execute on value change.
stylenullStringInline style of the component.
styleClassnullStringStyle class of the container.
onLabelnullStringLabel to display when button is selected.
offLabelnullStringLabel to display when button is unselected.
onIconnullStringIcon to display when button is selected.
offIconnullStringIcon to display when button is unselected.

SelectBooleanButton入门

selectBooleanButton.xhtml

<html xmlns="https://www.w3.org/1999/xhtml"
	xmlns:ui="https://java.sun.com/jsf/facelets"
	xmlns:h="https://java.sun.com/jsf/html"
	xmlns:f="https://java.sun.com/jsf/core"
	xmlns:p="https://primefaces.org/ui">
<h:head>
	<script name="jquery/jquery.js" library="primefaces"></script>
</h:head>
<h:form style="width:500px">
	<p:growl id="message"></p:growl>
	<p:outputLabel value="Turn your system:"></p:outputLabel>
		<p:selectBooleanButton offLabel="On" onLabel="Off" value="#{selectBooleanButton.status}" ></p:selectBooleanButton>
		<p:separator></p:separator>
	<p:commandButton value="Display System Status" action="#{selectBooleanButton.displaySystemStatus}" update="message"></p:commandButton>
</h:form>
</html>

SelectBooleanButton.java

package com.theitroad.prime.faces.beans;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

@ManagedBean
@SessionScoped
public class SelectBooleanButton {
	private boolean status;

	public boolean isStatus() {
		return status;
	}

	public void setStatus(boolean status) {
		this.status = status;
	}

	public String displaySystemStatus(){
		FacesContext.getCurrentInstance().addMessage(null,
				new FacesMessage("Your System Is: "+(status == true ? "Truned On":"Turned Off")));
		return "";
	}
}

SelectBooleanCheckbox基本信息

SelectBooleanCheckbox是具有主题集成功能的标准复选框的扩展版本。

TagSelectBooleanCheckbox
Component Classorg.primefaces.component.selectbooleancheckbox.SelectBooleanCheckbox
Component Typeorg.primefaces.component.SelectBooleanCheckbox
Component Familyorg.primefaces.component
Renderer Typeorg.primefaces.component.SelectBooleanCheckboxRenderer
Renderer Classorg.primefaces.component.selectbooleancheckbox.SelectBooleanCheckbox Renderer

SelectBooleanCheckbox属性

NameDefaultTypeDescription
idnullStringUnique identifier of the component
renderedtrueBooleanBoolean value to specify the rendering of the component, when set to false component will not be rendered.
bindingnullObjectAn el expression that maps to a server side UIComponent instance in a backing bean
valuenullObjectValue of the component referring to a List.
converternullConverter/StringAn el expression or a literal text that defines a converter for the component. When it’s an EL expression, it’s resolved to a converter instance. In case it’s a static text, it must refer to a converter id
immediatefalseBooleanWhen set true, process validations logic is executed at apply request values phase for this component.
requiredfalseBooleanMarks component as required
validatornullMethodExprA method expression that refers to a method validationg the input
valueChangeListenernullMethodExprA method expression that refers to a method for handling a valuechangeevent
requiredMessagenullStringMessage to be displayed when required field validation fails.
converterMessagenullStringMessage to be displayed when conversion fails.
validatorMessagenullStringMessage to be displayed when validation fields.
widgetVarnullStringName of the client side widget.
disabledfalseBooleanDisables the component.
labelnullStringUser presentable name.
onchangenullStringCallback to execute on value change.
stylenullStringInline style of the component.
styleClassnullStringStyle class of the container.
itemLabelnullStringLabel displayed next to checkbox.
tabindexnullStringSpecifies tab order for tab key navigation.

SelectBooleanCheckbox入门

selectBooleanCheckbox.xhtml

<html xmlns="https://www.w3.org/1999/xhtml"
	xmlns:ui="https://java.sun.com/jsf/facelets"
	xmlns:h="https://java.sun.com/jsf/html"
	xmlns:f="https://java.sun.com/jsf/core"
	xmlns:p="https://primefaces.org/ui">
<h:head>
	<script name="jquery/jquery.js" library="primefaces"></script>
</h:head>
<h:form style="width:500px">
	<p:growl id="message"></p:growl>
	<p:outputLabel value="Turn your system:"></p:outputLabel>
		<p:selectBooleanCheckbox value="#{selectBooleanCheckbox.status}" ></p:selectBooleanCheckbox>
		<p:separator></p:separator>
	<p:commandButton value="Display System Status" action="#{selectBooleanCheckbox.displaySystemStatus}" update="message"></p:commandButton>
</h:form>
</html>

SelectBooleanCheckbox.java

package com.theitroad.prime.faces.beans;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

@ManagedBean
@SessionScoped
public class SelectBooleanCheckbox {
	private boolean status;

	public boolean isStatus() {
		return status;
	}

	public void setStatus(boolean status) {
		this.status = status;
	}

	public String displaySystemStatus(){
		FacesContext.getCurrentInstance().addMessage(null,
				new FacesMessage("Your System Is: "+(status == true ? "Truned On":"Turned Off")));
		return "";
	}
}

SelectBooleanCheckbox客户端API

窗口小部件:PrimeFaces.widget.SelectBooleanCheckbox

MethodParamsReturn TypeDescription
check()voidChecks the checkbox.
uncheck()voidUnchecks the checkbox.
toggle()voidToggles check state.
  • PF隐式对象用于从客户端控制组件。
    使用的表达式是PF('WidgetVarValue')

SelectCheckboxMenu基本信息

SelectCheckboxMenu是一个多选组件,可在覆盖图中显示选项。

TagSelectCheckboxMenu
Component Classorg.primefaces.component.selectcheckboxmenu.SelectCheckboxMenu
Component Typeorg.primefaces.component.SelectCheckboxMenu
Component Familyorg.primefaces.component
Renderer Typeorg.primefaces.component.SelectCheckboxMenuRenderer
Renderer Classorg.primefaces.component.selectcheckboxmenu.SelectCheckboxMenuRenderer

SelectCheckboxMenu属性

NameDefaultTypeDescription
idnullStringUnique identifier of the component
renderedtrueBooleanBoolean value to specify the rendering of the component, when set to false component will not be rendered.
bindingnullObjectAn el expression that maps to a server side UIComponent instance in a backing bean
valuenullObjectValue of the component referring to a List.
converternullConverter/StringAn el expression or a literal text that defines a converter for the component. When it’s an EL expression, it’s resolved to a converter instance. In case it’s a static text, it must refer to a converter id
immediatefalseBooleanWhen set true, process validations logic is executed at apply request values phase for this component.
requiredfalseBooleanMarks component as required
validatornullMethodExprA method expression that refers to a method validationg the input
valueChangeListenernullMethodExprA method expression that refers to a method for handling a valuechangeevent
requiredMessagenullStringMessage to be displayed when required field validation fails.
converterMessagenullStringMessage to be displayed when conversion fails.
validatorMessagenullStringMessage to be displayed when validation fields.
widgetVarnullStringName of the client side widget.
disabledfalseBooleanDisables the component.
labelnullStringUser presentable name.
onchangenullStringCallback to execute on value change.
stylenullStringInline style of the component.
styleClassnullStringStyle class of the container.
scrollHeightnullIntegerHeight of the overlay.
onShownullStringClient side callback to execute when overlay is displayed.
onHidenullStringClient side callback to execute when overlay is hidden.
filterfalseBooleanRenders an input field as a filter.
filterMatchModestartsWithStringMatch mode for filtering, valid values are startsWith, contains, endsWith and custom.
filterFunctionnullStringClient side function to use in custom filtering.
caseSensitivefalseBooleanDefines if filtering would be case sensitive.
panelStylenullStringInline style of the overlay.
panelStyleClassnullStringStyle class of the overlay.
appendTonullStringAppends the overlay to the element defined by search expression. Defaults to document body.
tabindexnullStringPosition of the element in the tabbing order.

SelectCheckboxMenu入门

selectCheckboxMenu.xhtml

<html xmlns="https://www.w3.org/1999/xhtml"
	xmlns:ui="https://java.sun.com/jsf/facelets"
	xmlns:h="https://java.sun.com/jsf/html"
	xmlns:f="https://java.sun.com/jsf/core"
	xmlns:p="https://primefaces.org/ui">
<h:head>
	<script name="jquery/jquery.js" library="primefaces"></script>
</h:head>
<h:form style="width:400px">
	<p:growl id="message" showDetail="true" showSummary="true"></p:growl>
	<p:outputLabel value="Select wanted tutorials:"></p:outputLabel>
		<p:selectCheckboxMenu value="#{selectCheckboxMenu.selectedTutorials}">
			<f:selectItems value="#{selectCheckboxMenu.tutorials}" var="tutorial" itemLabel="#{tutorial}" itemValue="#{tutorial}"></f:selectItems>
		</p:selectCheckboxMenu>
		<p:separator></p:separator>
	<p:commandButton value="Register" action="#{selectCheckboxMenu.register}" update="message"></p:commandButton>
</h:form>
</html>

SelectCheckboxMenu.java

package com.theitroad.prime.faces.beans;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

@ManagedBean
@SessionScoped
public class SelectCheckboxMenu {

	private List<String> tutorials = new ArrayList<String>();

	private List<String> selectedTutorials = new ArrayList<String>();

	public SelectCheckboxMenu(){

	}

	@PostConstruct
	public void init(){
		this.tutorials = new ArrayList<String>();
		this.tutorials.add("Primefaces");
		this.tutorials.add("Hibernate");
		this.tutorials.add("Spring");
	}

	public List<String> getTutorials() {
		return tutorials;
	}

	public void setTutorials(List<String> tutorials) {
		this.tutorials = tutorials;
	}

	public List<String> getSelectedTutorials() {
		return selectedTutorials;
	}

	public void setSelectedTutorials(List<String> selectedTutorials) {
		this.selectedTutorials = selectedTutorials;
	}

	public String register(){
		String message = "";
		for(String s : this.selectedTutorials){
			message = message + s + ",";
		}
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("You've Registered In:", message));
		return "";
	}
}

SelectCheckboxMenu过滤

您可以对查看的列表进行某种过滤。
这种机制将帮助您轻松快速地找到所需的通缉物品。
要使您的组件适用于过滤其结果,只需执行以下步骤:

  • 确保将filter属性设置为true。

  • 设置您的过滤模式; startsWith(默认情况下),endsWith和自定义。

  • 如果您将自定义设置为过滤器模式,则必须提供通常与JavaScript函数相关联的filterFunction属性。

selectCheckboxMenu.xhtml

<html xmlns="https://www.w3.org/1999/xhtml"
	xmlns:ui="https://java.sun.com/jsf/facelets"
	xmlns:h="https://java.sun.com/jsf/html"
	xmlns:f="https://java.sun.com/jsf/core"
	xmlns:p="https://primefaces.org/ui">
<h:head>
	<script name="jquery/jquery.js" library="primefaces"></script>
</h:head>
<h:form style="width:400px">
	<p:growl id="message" showDetail="true" showSummary="true"></p:growl>
	<p:outputLabel value="Select wanted tutorials:"></p:outputLabel>
		<p:selectCheckboxMenu value="#{selectCheckboxMenu.selectedTutorials}" filter="true">
			<f:selectItems value="#{selectCheckboxMenu.tutorials}" var="tutorial" itemLabel="#{tutorial}" itemValue="#{tutorial}"></f:selectItems>
		</p:selectCheckboxMenu>
		<p:separator></p:separator>
	<p:commandButton value="Register" action="#{selectCheckboxMenu.register}" update="message"></p:commandButton>
</h:form>
</html>

SelectCheckboxMenu Ajax行为事件

大多数Primefaces组件都与许多Ajax事件相关联。
在Ajax Behavior Tutorial中将深入讨论如何利用这些事件,您可以重新开始。
这是可用于SelectCheckboxMenu的Ajax事件的详细列表。

EventListener ParameterFired
toggleSelectorg.primefaces.event.ToggleSelectEventWhen toggle all checkbox changes

SelectManyButton基本信息

SelectManyButton是使用按钮UI的多选组件。

TagSelectManyButton
Component Classorg.primefaces.component.selectmanybutton.SelectManyButton
Component Typeorg.primefaces.component.SelectManyButton
Component Familyorg.primefaces.component
Renderer Typeorg.primefaces.component.SelectManyButton
Renderer Classorg.primefaces.component.selectmanybutton.SelectManyButton

SelectManyButton属性

NameDefaultTypeDescription
idnullStringUnique identifier of the component
renderedtrueBooleanBoolean value to specify the rendering of the component, when set to false component will not be rendered.
bindingnullObjectAn el expression that maps to a server side UIComponent instance in a backing bean
valuenullObjectValue of the component referring to a List.
converternullConverter/StringAn el expression or a literal text that defines a converter for the component. When it’s an EL expression, it’s resolved to a converter instance. In case it’s a static text, it must refer to a converter id
immediatefalseBooleanWhen set true, process validations logic is executed at apply request values phase for this component.
requiredfalseBooleanMarks component as required
validatornullMethodExprA method expression that refers to a method validationg the input
valueChangeListenernullMethodExprA method expression that refers to a method for handling a valuechangeevent
requiredMessagenullStringMessage to be displayed when required field validation fails.
converterMessagenullStringMessage to be displayed when conversion fails.
validatorMessagenullStringMessage to be displayed when validation fields.
widgetVarnullStringName of the client side widget.
disabledfalseBooleanDisables the component.
labelnullStringUser presentable name.
onchangenullStringCallback to execute on value change.
stylenullStringInline style of the component.
styleClassnullStringStyle class of the container.

SelectManyButton入门

selectManyButton.xhtml

<html xmlns="https://www.w3.org/1999/xhtml"
	xmlns:ui="https://java.sun.com/jsf/facelets"
	xmlns:h="https://java.sun.com/jsf/html"
	xmlns:f="https://java.sun.com/jsf/core"
	xmlns:p="https://primefaces.org/ui">
<h:head>
	<script name="jquery/jquery.js" library="primefaces"></script>
</h:head>
<h:form style="width:400px">
	<p:growl id="message" showDetail="true" showSummary="true"></p:growl>
	<p:selectManyButton value="#{selectManyButton.selectedTutorials}">
		<f:selectItems value="#{selectManyButton.tutorials}"></f:selectItems>
	</p:selectManyButton>
	<p:separator></p:separator>
	<p:commandButton value="Register" action="#{selectManyButton.register}" update="message"></p:commandButton>
</h:form>
</html>

SelectManyButton.java

package com.theitroad.prime.faces.beans;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

@ManagedBean
@SessionScoped
public class SelectManyButton {
	private List<String> tutorials = new ArrayList<String>();

	private List<String> selectedTutorials = new ArrayList<String>();

	@PostConstruct
	public void init(){
		this.tutorials = new ArrayList<String>();
		this.tutorials.add("Primefaces");
		this.tutorials.add("Hibernate");
		this.tutorials.add("Spring");
	}

	public List<String> getTutorials() {
		return tutorials;
	}

	public void setTutorials(List<String> tutorials) {
		this.tutorials = tutorials;
	}

	public List<String> getSelectedTutorials() {
		return selectedTutorials;
	}

	public void setSelectedTutorials(List<String> selectedTutorials) {
		this.selectedTutorials = selectedTutorials;
	}

	public String register(){
		String message = "";
		for(String s : this.selectedTutorials){
			message = message + s + ",";
		}
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("You've Registered In:", message));
		return "";
	}
}

SelectManyCheckbox基本信息

SelectManyCheckbox是具有主题集成功能的标准SelectManyCheckbox的扩展版本。

TagSelectManyCheckbox
Component Classorg.primefaces.component.selectmanycheckbox.SelectManyCheckbox
Component Typeorg.primefaces.component.SelectManyCheckbox
Component Familyorg.primefaces.component
Renderer Typeorg.primefaces.component.SelectManyCheckboxRenderer
Renderer Classorg.primefaces.component.selectmanycheckbox.SelectManyCheckboxRenderer

SelectManyChcekbox属性

NameDefaultTypeDescription
idnullStringUnique identifier of the component
renderedtrueBooleanBoolean value to specify the rendering of the component, when set to false component will not be rendered.
bindingnullObjectAn el expression that maps to a server side UIComponent instance in a backing bean
valuenullObjectValue of the component referring to a List.
converternullConverter/St ringAn el expression or a literal text that defines a converter for the component. When it’s an EL expression, it’s resolved to a converter instance. In case it’s a static text, it must refer to a converter id
immediatefalseBooleanWhen set true, process validations logic is executed at apply request values phase for this component.
requiredfalseBooleanMarks component as required
validatornullMethodExprA method expression that refers to a method validationg the input
valueChangeListenernullMethodExprA method expression that refers to a method for handling a valuechangeevent
requiredMessagenullStringMessage to be displayed when required field validation fails
converterMessagenullStringMessage to be displayed when conversion fails.
validatorMessagenullStringMessage to be displayed when validation fields.
widgetVarnullStringName of the client side widget.
disabledfalseBooleanDisables the component.
labelnullStringUser presentable name.
layoutlineDirectionStringLayout of the checkboxes, valid values are lineDirection, pageDirection and grid.
columns0IntegerNumber of columns in grid layout.
onchangenullStringCallback to execute on value change.
stylenullStringInline style of the component.
styleClassnullStringStyle class of the container.

SelectManyCheckbox入门

selectManyCheckbox.xhtml

<html xmlns="https://www.w3.org/1999/xhtml"
	xmlns:ui="https://java.sun.com/jsf/facelets"
	xmlns:h="https://java.sun.com/jsf/html"
	xmlns:f="https://java.sun.com/jsf/core"
	xmlns:p="https://primefaces.org/ui">
<h:head>
	<script name="jquery/jquery.js" library="primefaces"></script>
</h:head>
<h:form style="width:400px">
	<p:growl id="message" showDetail="true" showSummary="true"></p:growl>
	<p:selectManyCheckbox value="#{selectManyCheckbox.selectedTutorials}">
		<f:selectItems value="#{selectManyCheckbox.tutorials}"></f:selectItems>
	</p:selectManyCheckbox>
	<p:separator></p:separator>
	<p:commandButton value="Register" action="#{selectManyCheckbox.register}" update="message"></p:commandButton>
</h:form>
</html>

SelectManyCheckbox.java

package com.theitroad.prime.faces.beans;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

@ManagedBean
@SessionScoped
public class SelectManyCheckbox {

	private List<String> tutorials = new ArrayList<String>();

	private List<String> selectedTutorials = new ArrayList<String>();

	public SelectManyCheckbox(){

	}

	@PostConstruct
	public void init(){
		this.tutorials = new ArrayList<String>();
		this.tutorials.add("Primefaces");
		this.tutorials.add("Hibernate");
		this.tutorials.add("Spring");
	}

	public List<String> getTutorials() {
		return tutorials;
	}

	public void setTutorials(List<String> tutorials) {
		this.tutorials = tutorials;
	}

	public List<String> getSelectedTutorials() {
		return selectedTutorials;
	}

	public void setSelectedTutorials(List<String> selectedTutorials) {
		this.selectedTutorials = selectedTutorials;
	}

	public String register(){
		String message = "";
		for(String s : this.selectedTutorials){
			message = message + s + ",";
		}
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("You've Registered In:", message));
		return "";
	}
}

SelectManyMenu基本信息

SelectManyMenu是标准SelectManyMenu的扩展版本。

TagSelectManyMenu
Component Classorg.primefaces.component.selectmanymenu.SelectManyMenu
Component Typeorg.primefaces.component.SelectManyMenu
Component Familyorg.primefaces.component
Renderer Typeorg.primefaces.component.SelectManyMenuRenderer
Renderer Classorg.primefaces.component.selectmanymenu.SelectManyMenuRenderer

SelectManyMenu属性

NameDefaultTypeDescription
idnullStringUnique identifier of the component
renderedtrueBooleanBoolean value to specify the rendering of the component, when set to false component will not be rendered.
bindingnullObjectAn el expression that maps to a server side UIComponent instance in a backing bean
valuenullObjectValue of the component referring to a List.
immediatefalseBooleanWhen set true, process validations logic is executed at apply request values phase for this component.
requiredfalseBooleanMarks component as required
validatornullMethodExprA method expression that refers to a method validationg the input
valueChangeListenernullMethodExprA method expression that refers to a method for handling a valuechangeevent
requiredMessagenullStringMessage to be displayed when required field validation fails.
converterMessagenullStringMessage to be displayed when conversion fails.
validatorMessagenullStringMessage to be displayed when validation fields.
widgetVarnullStringName of the client side widget.
disabledfalseBooleanDisables the component.
labelnullStringUser presentable name.
onchangenullStringCallback to execute on value change.
onclicknullStringCallback for click event.
ondblclicknullStringCallback for dblclick event.
stylenullStringInline style of the component.
styleClassnullStringStyle class of the container.
tabindexnullStringPosition of the input element in the tabbing order.
varnullStringName of iterator to be used in custom content display.
showCheckboxfalseBooleanWhen true, a checkbox is displayed next to each item.
filterfalseBooleanDisplays an input filter for the list.
filterMatchModenullStringMatch mode for filtering, valid values are startsWith (default), contains, endsWith and custom.
filterFunctionnullStringClient side function to use in custom filterMatchMode.
caseSensitivefalseBooleanDefines if filtering would be case sensitive.
scrollHeightnullIntegerDefines the height of the scrollable area
converternullConverter/StringAn el expression or a literal text that defines a converter for the component. When it's an EL expression, it's resolved to a converter instance. In case it's static text, it must refer to a converter id

SelectManyMenu入门

selectManyMenu.xhtml

<html xmlns="https://www.w3.org/1999/xhtml"
	xmlns:ui="https://java.sun.com/jsf/facelets"
	xmlns:h="https://java.sun.com/jsf/html"
	xmlns:f="https://java.sun.com/jsf/core"
	xmlns:p="https://primefaces.org/ui">
<h:head>
	<script name="jquery/jquery.js" library="primefaces"></script>
</h:head>
<h:form style="width:400px">
	<p:growl id="message" showDetail="true" showSummary="true"></p:growl>
	<p:selectManyMenu value="#{selectManyMenu.selectedTutorials}">
		<f:selectItems value="#{selectManyMenu.tutorials}"></f:selectItems>
	</p:selectManyMenu>
	<p:separator></p:separator>
	<p:commandButton value="Register" action="#{selectManyMenu.register}" update="message"></p:commandButton>
</h:form>
</html>

SelectManyMenu.java

package com.theitroad.prime.faces.beans;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

@ManagedBean
@SessionScoped
public class SelectManyMenu {

	private List<String> tutorials = new ArrayList<String>();

	private List<String> selectedTutorials = new ArrayList<String>();

	public SelectManyMenu(){

	}

	@PostConstruct
	public void init(){
		this.tutorials = new ArrayList<String>();
		this.tutorials.add("Primefaces");
		this.tutorials.add("Hibernate");
		this.tutorials.add("Spring");
	}

	public List<String> getTutorials() {
		return tutorials;
	}

	public void setTutorials(List<String> tutorials) {
		this.tutorials = tutorials;
	}

	public List<String> getSelectedTutorials() {
		return selectedTutorials;
	}

	public void setSelectedTutorials(List<String> selectedTutorials) {
		this.selectedTutorials = selectedTutorials;
	}

	public String register(){
		String message = "";
		for(String s : this.selectedTutorials){
			message = message + s + ",";
		}
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("You've Registered In:", message));
		return "";
	}
}

SelectManyMenu –自定义内容

您可以为每一项写入自己的自定义内容。
通过提供包含在SelectManyMenu打开/结束标签内的Primefaces/jsf组件的所需内容,您可以提供自己的自定义内容。
以下示例显示了相同的示例,但具有不同的图像。

selectManyMenu.xhtml

<html xmlns="https://www.w3.org/1999/xhtml"
	xmlns:ui="https://java.sun.com/jsf/facelets"
	xmlns:h="https://java.sun.com/jsf/html"
	xmlns:f="https://java.sun.com/jsf/core"
	xmlns:p="https://primefaces.org/ui">
<h:head>
	<script name="jquery/jquery.js" library="primefaces"></script>
</h:head>
<h:form style="width:400px">
	<p:growl id="message" showDetail="true" showSummary="true"></p:growl>
	<p:selectManyMenu value="#{selectManyMenu.selectedTutorials}" var="tutorial">
		<f:selectItems value="#{selectManyMenu.tutorials}"
		<p:column>
			<p:graphicImage value="/resources/images/#{tutorial}.jpg" width="40"></p:graphicImage>
		</p:column>
		<p:column>
			<p:outputLabel value="#{tutorial}"></p:outputLabel>
		</p:column>
	</p:selectManyMenu>
	<p:separator></p:separator>
	<p:commandButton value="Register" action="#{selectManyMenu.register}" update="message"></p:commandButton>
</h:form>
</html>

SelectManyMenu –过滤

您可以在SelectManyMenu中使用筛选器功能,与SelectCheckboxMenu的用法相同。

SelectOneButton基本信息

SelectOneButton是执行单个选择的输入组件。

TagSelectOneButton
Component Classorg.primefaces.component.selectonebutton.SelectOneButton
Component Typeorg.primefaces.component.SelectOneButton
Component Familyorg.primefaces.component
Renderer Typeorg.primefaces.component.SelectOneButtonRenderer
Renderer Classorg.primefaces.component.selectonebutton.SelectOneButtonRenderer

SelectOneButton属性

NameDefaultTypeDescription
idnullStringUnique identifier of the component
renderedtrueBooleanBoolean value to specify the rendering of the component, when set to false component will not be rendered.
bindingnullObjectAn el expression that maps to a server side UIComponent instance in a backing bean
valuenullObjectValue of the component referring to a List.
immediatefalseBooleanWhen set true, process validations logic is executed at apply request values phase for this component.
requiredfalseBooleanMarks component as required
validatornullMethodExprA method expression that refers to a method validationg the input
valueChangeListenernullMethodExprA method expression that refers to a method for handling a valuechangeevent
requiredMessagenullStringMessage to be displayed when required field validation fails.
converterMessagenullStringMessage to be displayed when conversion fails.
validatorMessagenullStringMessage to be displayed when validation fields.
widgetVarnullStringName of the client side widget.
disabledfalseBooleanDisables the component.
labelnullStringUser presentable name.
onchangenullStringCallback to execute on value change.
stylenullStringInline style of the component.
styleClassnullStringStyle class of the container.
converternullConverter/St ringAn el expression or a literal text that defines a converter for the component. When it’s an EL expression, it’s resolved to a converter instance. In case it’s a static text, it must refer to a converter id

SelectOneButton入门

selectOneButton.xhtml

<html xmlns="https://www.w3.org/1999/xhtml"
	xmlns:ui="https://java.sun.com/jsf/facelets"
	xmlns:h="https://java.sun.com/jsf/html"
	xmlns:f="https://java.sun.com/jsf/core"
	xmlns:p="https://primefaces.org/ui">
<h:head>
	<script name="jquery/jquery.js" library="primefaces"></script>
</h:head>
<h:form style="width:400px">
	<p:growl id="message" showDetail="true" showSummary="true"></p:growl>
	<p:selectOneButton value="#{selectOneButton.selectedTutorial}">
		<f:selectItems value="#{selectOneButton.tutorials}"></f:selectItems>
	</p:selectOneButton>
	<p:separator></p:separator>
	<p:commandButton value="Register" action="#{selectOneButton.register}" update="message"></p:commandButton>
</h:form>
</html>

SelectOneButton.java

package com.theitroad.prime.faces.beans;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

@ManagedBean
@SessionScoped
public class SelectOneButton {
	private List<String> tutorials = new ArrayList<String>();

	private String selectedTutorial = "";

	@PostConstruct
	public void init(){
		this.tutorials = new ArrayList<String>();
		this.tutorials.add("Primefaces");
		this.tutorials.add("Hibernate");
		this.tutorials.add("Spring");
	}

	public List<String> getTutorials() {
		return tutorials;
	}

	public void setTutorials(List<String> tutorials) {
		this.tutorials = tutorials;
	}

	public String getSelectedTutorial() {
		return selectedTutorial;
	}

	public void setSelectedTutorial(String selectedTutorial) {
		this.selectedTutorial = selectedTutorial;
	}

	public String register(){
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("You've Registered In:", this.selectedTutorial));
		return "";
	}
}

SelectOneListbox基本信息

SelectOneListbox是标准selectOneListbox组件的扩展版本。

TagSelectOneListbox
Component Classorg.primefaces.component.selectonelistbox.SelectOneListbox
Component Typeorg.primefaces.component.SelectOneListbox
Component Familyorg.primefaces.component
Renderer Typeorg.primefaces.component.SelectOneListboxRenderer
Renderer Classorg.primefaces.component.selectonelistbox.SelectOneListBoxRenderer

SelectOneListbox属性

NameDefaultTypeDescription
idnullStringUnique identifier of the component
renderedtrueBooleanBoolean value to specify the rendering of the component, when set to false component will not be rendered.
bindingnullObjectAn el expression that maps to a server side UIComponent instance in a backing bean
valuenullObjectValue of the component referring to a List.
converternullConverter/StringAn el expression or a literal text that defines a converter for the component. When it’s an EL expression, it’s resolved to a converter instance. In case it’s a static text, it must refer to a converter id
immediatefalseBooleanWhen set true, process validations logic is executed at apply request values phase for this component.
requiredfalseBooleanMarks component as required
validatornullMethodExprA method expression that refers to a method validationg the input
valueChangeListenernullMethodExprA method expression that refers to a method for handling a valuechangeevent
requiredMessagenullStringMessage to be displayed when required field validation fails.
converterMessagenullStringMessage to be displayed when conversion fails.
validatorMessagenullStringMessage to be displayed when validation fields.
widgetVarnullStringName of the client side widget.
disabledfalseBooleanDisables the component.
labelnullStringUser presentable name.
onchangenullStringCallback to execute on value change.
onclicknullStringCallback for click event.
ondblclicknullStringCallback for dblclick event.
stylenullStringInline style of the component.
styleClassnullStringStyle class of the container.
tabindexnullStringPosition of the input element in the tabbing order.
valuenullStringName of iterator to be used in custom content display.
varnullStringName of iterator to be used in custom content display.
filterfalseBooleanDisplays an input filter for the list.
filterMatchModenullStringMatch mode for filtering, valid values are startsWith (default), contains, endsWith and custom.
filterFunctionnullStringClient side function to use in custom filterMatchMode.
caseSensitivefalseBooleanDefines if filtering would be case sensitive.
scrollHeightnullIntegerDefines the height of the scrollable area.

SelectOneListbox入门

selectOneListbox.xhtml

<html xmlns="https://www.w3.org/1999/xhtml"
	xmlns:ui="https://java.sun.com/jsf/facelets"
	xmlns:h="https://java.sun.com/jsf/html"
	xmlns:f="https://java.sun.com/jsf/core"
	xmlns:p="https://primefaces.org/ui">
<h:head>
	<script name="jquery/jquery.js" library="primefaces"></script>
</h:head>
<h:form style="width:400px">
	<p:growl id="message" showDetail="true" showSummary="true"></p:growl>
	<p:selectOneListbox value="#{selectOneListBox.selectedTutorial}">
		<f:selectItems value="#{selectOneListBox.tutorials}"></f:selectItems>
	</p:selectOneListbox>
	<p:separator></p:separator>
	<p:commandButton value="Register" action="#{selectOneListBox.register}" update="message"></p:commandButton>
</h:form>
</html>

SelectOneListbox.java

package com.theitroad.prime.faces.beans;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

@ManagedBean
@SessionScoped
public class SelectOneListbox {
	private List<String> tutorials = new ArrayList<String>();

	private String selectedTutorial = "";

	@PostConstruct
	public void init(){
		this.tutorials = new ArrayList<String>();
		this.tutorials.add("Primefaces");
		this.tutorials.add("Hibernate");
		this.tutorials.add("Spring");
	}

	public List<String> getTutorials() {
		return tutorials;
	}

	public void setTutorials(List<String> tutorials) {
		this.tutorials = tutorials;
	}

	public String getSelectedTutorial() {
		return selectedTutorial;
	}

	public void setSelectedTutorial(String selectedTutorial) {
		this.selectedTutorial = selectedTutorial;
	}

	public String register(){
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("You've Registered In:", this.selectedTutorial));
		return "";
	}
}

SelectOneMenu基本信息

SelectOneMenu是标准SelectOneMenu的扩展版本。

TagSelectOneMenu
Component Classorg.primefaces.component.selectonemenu.SelectOneMenu
Component Typeorg.primefaces.component.SelectOneMenu
Component Familyorg.primefaces.component
Renderer Typeorg.primefaces.component.SelectOneMenuRenderer
Renderer Classorg.primefaces.component.selectonemenu.SelectOneMenuRenderer

SelectOneMenu属性

NameDefaultTypeDescription
idnullStringUnique identifier of the component
renderedtrueBooleanBoolean value to specify the rendering of the component, when set to false component will not be rendered.
bindingnullObjectAn el expression that maps to a server side UIComponent instance in a backing bean
valuenullObjectValue of the component.
converternullConverter/StringAn el expression or a literal text that defines a converter for the component. When it’s an EL expression, it’s resolved to a converter instance. In case it’s a static text, it must refer to a converter id
immediate0BooleanWhen set true, process validations logic is executed at apply request values phase for this component.
required0BooleanMarks component as required
validatornullMethodExprA method expression that refers to a method validationg the input
valueChangeListenernullMethodExprA method expression that refers to a method for handling a valuechangeevent
requiredMessagenullStringMessage to be displayed when required field validation fails.
converterMessagenullStringMessage to be displayed when conversion fails.
validatorMessagenullStringMessage to be displayed when validation fields.
widgetVarnullStringName of the client side widget.
effectblindStringName of the toggle animation.
effectSpeed400IntegerDuration of toggle animation in milliseconds.
disabledfalseBooleanDisables the component.
labelnullStringUser presentable name.
onchangenullStringClient side callback to execute on value change.
onkeyupnullStringClient side callback to execute on keyup.
onkeydownnullStringClient side callback to execute on keydown.
stylenullStringInline style of the component.
styleClassnullStringStyle class of the container.
varnullStringName of the item iterator.
heightautoIntegerHeight of the overlay.
tabindexnullStringTabindex of the input.
editablefalseBooleanWhen true, input becomes editable.
filterfalseBooleanRenders an input field as a filter.
filterMatchModestarts WithStringMatch mode for filtering, valid values are startsWith, contains, endsWith and custom.
filterFunctionnullStringClient side function to use in custom filtering.
caseSensitivefalseBooleanDefines if filtering would be case sensitive.
maxlengthnullIntegerNumber of maximum characters allowed in editable selectOneMenu.
appendTonullStringAppends the overlay to the element defined by search expression. Defaults to document body.

SelectOneMenu入门

selectOneMenu.xhtml

<html xmlns="https://www.w3.org/1999/xhtml"
	xmlns:ui="https://java.sun.com/jsf/facelets"
	xmlns:h="https://java.sun.com/jsf/html"
	xmlns:f="https://java.sun.com/jsf/core"
	xmlns:p="https://primefaces.org/ui">
<h:head>
	<script name="jquery/jquery.js" library="primefaces"></script>
</h:head>
<h:form style="width:400px">
	<p:growl id="message" showDetail="true" showSummary="true"></p:growl>
	<p:selectOneMenu value="#{selectOneMenu.selectedTutorial}">
		<f:selectItems value="#{selectOneMenu.tutorials}"></f:selectItems>
	</p:selectOneMenu>
	<p:separator></p:separator>
	<p:commandButton value="Register" action="#{selectOneMenu.register}" update="message"></p:commandButton>
</h:form>
</html>

SelectOneMenu.java

package com.theitroad.prime.faces.beans;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

@ManagedBean
@SessionScoped
public class SelectOneMenu {
	private List<String> tutorials = new ArrayList<String>();

	private String selectedTutorial = "";

	@PostConstruct
	public void init(){
		this.tutorials = new ArrayList<String>();
		this.tutorials.add("Primefaces");
		this.tutorials.add("Hibernate");
		this.tutorials.add("Spring");
	}

	public List<String> getTutorials() {
		return tutorials;
	}

	public void setTutorials(List<String> tutorials) {
		this.tutorials = tutorials;
	}

	public String getSelectedTutorial() {
		return selectedTutorial;
	}

	public void setSelectedTutorial(String selectedTutorial) {
		this.selectedTutorial = selectedTutorial;
	}

	public String register(){
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("You've Registered In:", this.selectedTutorial));
		return "";
	}
}

SelectOneRadio基本信息

TagSelectOneRadio
Component Classorg.primefaces.component.selectoneradio.SelectOneRadio
Component Typeorg.primefaces.component.SelectOneRadio
Component Familyorg.primefaces.component
Renderer Typeorg.primefaces.component.SelectOneRadioRenderer
Renderer Classorg.primefaces.component.selectoneradio.SelectOneRadioRenderer

SelectOneRadio属性

NameDefaultTypeDescription
idnullStringUnique identifier of the component
renderedtrueBooleanBoolean value to specify the rendering of the component, when set to false component will not be rendered.
bindingnullObjectAn el expression that maps to a server side UIComponent instance in a backing bean
valuenullObjectValue of the component referring to a List.
converternullConverter/StringAn el expression or a literal text that defines a converter for the component. When it’s an EL expression, it’s resolved to a converter instance. In case it’s a static text, it must refer to a converter id
immediate0BooleanWhen set true, process validations logic is executed at apply request values phase for this component.
required0BooleanMarks component as required
validatornullMethodExprA method expression that refers to a method validationg the input
valueChangeListenernullMethodExprA method expression that refers to a method for handling a valuechangeevent
requiredMessagenullStringMessage to be displayed when required field validation fails.
converterMessagenullStringMessage to be displayed when conversion fails.
validatorMessagenullStringMessage to be displayed when validation fields.
widgetVarnullStringName of the client side widget.
disabledfalseBooleanDisables the component.
labelnullStringUser presentable name.
layoutline DirectionStringLayout of the radiobuttons, valid values are lineDirection, pageDirection, custom and grid.
columns0IntegerNumber of columns in grid layout.
onchangenullStringCallback to execute on value change.
stylenullStringInline style of the component.
styleClassnullStringStyle class of the container.
tabindexnullStringSpecifies the tab order of element in tab navigation.
plainfalseBooleanPlain mode displays radiobuttons using native browser rendering instead of themes.

SelectOneRadio入门

SelectOneRadio的用法与SelectOneMenu的用法相同,不同之处在于,呈现了一组单选控件,而不是使用菜单控件。