Primefaces Radio Button, Checkbox Example

Primefaces Radio Button and checkbox are select elements. Below are the primefaces components for different kinds of radio button and checkbox implementations.

  1. SelectBooleanButton
  2. SelectBooleanCheckbox
  3. SelectCheckboxMenu
  4. SelectManyButton
  5. SelectManyCheckbox
  6. SelectManyMenu
  7. SelectOneButton
  8. SelectOneListbox
  9. SelectOneMenu
  10. SelectOneRadio

Let’s explore these components thoroughly and see how can we leverage them into your application.

SelectBooleanButton Basic Info

SelectBooleanButton is used to select a binary decision with a toggle button.

Tag SelectBooleanButton
Component Class org.primefaces.component.selectbooleanbutton.SelectBooleanButton
Component Type org.primefaces.component.SelectBooleanButton
Component Family org.primefaces.component
Renderer Type org.primefaces.component.SelectBooleanButtonRenderer
Renderer Class org.primefaces.component.selectbooleanbutton.SelectBooleanButtonRenderer

SelectBooleanButton Attributes

Name Default Type Description
id null String Unique identifier of the component
rendered true Boolean Boolean value to specify the rendering of the component, when set to false component will not be rendered.
binding null Object An el expression that maps to a server side UIComponent instance in a backing bean
value null Object Value of the component referring to a List.
converter null Converter/ String An 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
immediate fal
se
Boolean When set true, process validations logic is executed at apply request values phase for this component.
required false Boolean Marks component as required
validator null Method Expr A method expression that refers to a method validationg the input
valueChangeListener null Method Expr A method expression that refers to a method for handling a valuechangeevent
requiredMessage null String Message to be displayed when required field validation fails.
converterMessage null String Message to be displayed when conversion fails.
validatorMessage null String Message to be displayed when validation fields.
widgetVar null String Name of the client side widget.
disabled false Boolean Disables the component.
label null String User presentable name.
onchange null String Callback to execute on value change.
style null String Inline style of the component.
styleClass null String Style class of the container.
onLabel null String Label to display when button is selected.
offLabel null String Label to display when button is unselected.
onIcon null String Icon to display when button is selected.
offIcon null String Icon to display when button is unselected.

Getting Started With SelectBooleanButton

selectBooleanButton.xhtml

SelectBooleanButton.java

SelectBooleanButton-Turned-Off-View-1024x126

 

SelectBooleanButton-Turned-Off-View-1024x126

SelectBooleanCheckbox Basic Info

SelectBooleanCheckbox is an extended version of the standard checkbox with theme integration.

Tag SelectBooleanCheckbox
Component Class org.primefaces.component.selectbooleancheckbox.SelectBooleanCheckbox
Component Type org.primefaces.component.SelectBooleanCheckbox
Component Family org.primefaces.component
Renderer Type org.primefaces.component.SelectBooleanCheckboxRenderer
Renderer Class org.primefaces.component.selectbooleancheckbox.SelectBooleanCheckbox Renderer

SelectBooleanCheckbox Attributes

Name Default Type Description
id null String Unique identifier of the component
rendered true Boolean Boolean value to specify the rendering of the component, when set to false component will not be rendered.
binding null Object An el expression that maps to a server side UIComponent instance in a backing bean
value null Object Value of the component referring to a List.
converter null Converter/ String An 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
immediate false Boolean When set true, process validations logic is executed at apply
request values phase for this component.
required false Boolean Marks component as required
validator null MethodExpr A method expression that refers to a method validationg the input
valueChangeListener null MethodExpr A method expression that refers to a method for handling a valuechangeevent
requiredMessage null String Message to be displayed when required field validation fails.
converterMessage null String Message to be displayed when conversion fails.
validatorMessage null String Message to be displayed when validation fields.
widgetVar null String Name of the client side widget.
disabled false Boolean Disables the component.
label null String User presentable name.
onchange null String Callback to execute on value change.
style null String Inline style of the component.
styleClass null String Style class of the container.
itemLabel null String Label displayed next to checkbox.
tabindex null String Specifies tab order for tab key navigation.

Getting Started With SelectBooleanCheckbox

selectBooleanCheckbox.xhtml

SelectBooleanCheckbox.java

SelectBooleanCheckbox Client Side API

Widget: PrimeFaces.widget.SelectBooleanCheckbox

Method Params Return Type Description
check() void Checks the checkbox.
uncheck() void Unchecks the checkbox.
toggle() void Toggles check state.
  • PF implicit object is used for controlling the component from the client side. The expression used is PF('WidgetVarValue')

SelectCheckboxMenu Basic Info

SelectCheckboxMenu is a multi select component that displays options in an overlay.

Tag SelectCheckboxMenu
Component Class org.primefaces.component.selectcheckboxmenu.SelectCheckboxMenu
Component Type org.primefaces.component.SelectCheckboxMenu
Component Family org.primefaces.component
Renderer Type org.primefaces.component.SelectCheckboxMenuRenderer
Renderer Class org.primefaces.component.selectcheckboxmenu.SelectCheckboxMenuRenderer

SelectCheckboxMenu Attributes

Name Default Type Description
id null String Unique identifier of the component
rendered true Boolean Boolean value to specify the rendering of the component, when set to false component will not be rendered.
binding null Object An el expression that maps to a server side UIComponent instance in a backing bean
value null Object Value of the component referring to a List.
converter null Converter/ String An 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
immediate false Boolean When set true, process validations logic is executed at apply request values phase for this component.
required false Boolean Marks component as required
validator null MethodExpr A method expression that refers to a method validationg the input
valueChangeListener null MethodExpr A method expression that refers to a method for handling a valuechangeevent
requiredMessage null String Message to be displayed when required field validation fails.
converterMessage null String Message to be displayed when conversion fails.
validatorMessage null String Message to be displayed when validation fields.
widgetVar null String Name of the client side widget.
disabled false Boolean Disables the component.
label null String User presentable name.
onchange null String Callback to execute on value change.
style null String Inline style of the component.
styleClass null String Style class of the container.
scrollHeight null Integer Height of the overlay.
onShow null String Client side callback to execute when overlay is displayed.
onHide null String Client side callback to execute when overlay is hidden.
filter false Boolean Renders an input field as a filter.
filterMatchMode startsWith String Match mode for filtering, valid values are startsWith, contains, endsWith and custom.
filterFunction null String Client side function to use in custom filtering.
caseSensitive false Boolean Defines if filtering would be case sensitive.
panelStyle null String Inline style of the overlay.
panelStyleClass null String Style class of the overlay.
appendTo null String Appends the overlay to the element defined by search expression. Defaults to document body.
tabindex null String Position of the element in the tabbing order.

Getting started with SelectCheckboxMenu

selectCheckboxMenu.xhtml

SelectCheckboxMenu.java

SelectCheckboxMenu Filtering

It’s possible for you to make use some sort of filtering against your viewed list. This mechanism will help you got a fast reach into the desired wanted item easily. To make your component applicable to filter its result, just follow below steps:

  • Make sure filter attribute is set to true.
  • Setting your filter mode; startsWith (by default), endsWith and custom.
  • In case you’ve set custom as a mode of your filter you must provide filterFunction attribute which normally associated with a JavaScript function.

selectCheckboxMenu.xhtml

SelectCheckboxMenu-Filter-View

SelectCheckboxMenu Ajax Behavior Events

Most of Primefaces’ components have associated in with a lot of Ajax events. The way in which those events can be leveraged is discussed deeply at Ajax Behavior Tutorial where you can get back into. Here’s, a detailed list of Ajax events that you can use against SelectCheckboxMenu.

Event Listener Parameter Fired
toggleSelect org.primefaces.event.ToggleSelectEvent When toggle all checkbox changes

SelectManyButton Basic Info

SelectManyButton is a multi select component using button UI.

Tag SelectManyButton
Component Class org.primefaces.component.selectmanybutton.SelectManyButton
Component Type org.primefaces.component.SelectManyButton
Component Family org.primefaces.component
Renderer Type org.primefaces.component.SelectManyButton
Renderer Class org.primefaces.component.selectmanybutton.SelectManyButton

SelectManyButton Attributes

Name Default Type Description
id null String Unique identifier of the component
rendered true Boolean Boolean value to specify the rendering of the component, when set to false component will not be rendered.
binding null Object An el expression that maps to a server side UIComponent instance in a backing bean
value null Object Value of the component referring to a List.
converter null Converter/ String An 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
immediate false Boolean When set true, process validations logic is executed at apply request values phase for this component.
required false Boolean Marks component as required
validator null MethodExpr A method expression that refers to a method validationg the input
valueChangeListener null MethodExpr A method expression that refers to a method for handling a valuechangeevent
requiredMessage null String Message to be displayed when required field validation fails.
converterMessage null String Message to be displayed when conversion fails.
validatorMessage null String Message to be displayed when validation fields.
widgetVar null String Name of the client side widget.
disabled false Boolean Disables the component.
label null String User presentable name.
onchange null String Callback to execute on value change.
style null String Inline style of the component.
styleClass null String Style class of the container.

Getting Started With SelectManyButton

selectManyButton.xhtml

SelectManyButton.java

SelectManyButton-Initial-View

SelectManyCheckbox Basic Info

SelectManyCheckbox is an extended version of the standard SelectManyCheckbox with theme integration.

Tag SelectManyCheckbox
Component Class org.primefaces.component.selectmanycheckbox.SelectManyCheckbox
Component Type org.primefaces.component.SelectManyCheckbox
Component Family org.primefaces.component
Renderer Type org.primefaces.component.SelectManyCheckboxRenderer
Renderer Class org.primefaces.component.selectmanycheckbox.SelectManyCheckboxRenderer

SelectManyChcekbox Attributes

Name Default Type Description
id null String Unique identifier of the component
rendered true Boolean Boolean value to specify the rendering of the component, when set to false component will not be rendered.
binding null Object An el expression that maps to a server side UIComponent instance in a backing bean
value null Object Value of the component referring to a List.
converter null Converter/St ring An 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
immediate false Boolean When set true, process validations logic is executed at apply request values phase for this component.
required false Boolean Marks component as required
validator null MethodExpr A method expression that refers to a method validationg the input
valueChangeListener null MethodExpr A method expression that refers to a method for handling a valuechangeevent
requiredMessage null String Message to be displayed when required field validation fails
converterMessage null String Message to be displayed when conversion fails.
validatorMessage null String Message to be displayed when validation fields.
widgetVar null String Name of the client side widget.
disabled false Boolean Disables the component.
label null String User presentable name.
layout lineDirection String Layout of the checkboxes, valid values are lineDirection, pageDirection and grid.
columns 0 Integer Number of columns in grid layout.
onchange null String Callback to execute on value change.
style null String Inline style of the component.
styleClass null String Style class of the container.

Getting Started With SelectManyCheckbox

selectManyCheckbox.xhtml

SelectManyCheckbox.java

SelectManyCheckbox-Initial-View

SelectManyCheckbox-Initial-View

SelectManyMenu Basic Info

SelectManyMenu is an extended version of the standard SelectManyMenu.

Tag SelectManyMenu
Component Class org.primefaces.component.selectmanymenu.SelectManyMenu
Component Type org.primefaces.component.SelectManyMenu
Component Family org.primefaces.component
Renderer Type org.primefaces.component.SelectManyMenuRenderer
Renderer Class org.primefaces.component.selectmanymenu.SelectManyMenuRenderer

SelectManyMenu Attributes

Name Default Type Description
id null String Unique identifier of the component
rendered true Boolean Boolean value to specify the rendering of the component, when set to false component will not be rendered.
binding null Object An el expression that maps to a server side UIComponent instance in a backing bean
value null Object Value of the component referring to a List.
immediate false Boolean When set true, process validations logic is executed at apply request values phase for this component.
required false Boolean Marks component as required
validator null MethodExpr A method expression that refers to a method validationg the input
valueChangeListener null MethodExpr A method expression that refers to a method for handling a valuechangeevent
requiredMessage null String Message to be displayed when required field validation fails.
converterMessage null String Message to be displayed when conversion fails.
validatorMessage null String Message to be displayed when validation fields.
widgetVar null String Name of the client side widget.
disabled false Boolean Disables the component.
label null String User presentable name.
onchange null String Callback to execute on value change.
onclick null String Callback for click event.
ondblclick null String Callback for dblclick event.
sty
le
null String Inline style of the component.
styleClass null String Style class of the container.
tabindex null String Position of the input element in the tabbing order.
var null String Name of iterator to be used in custom content display.
showCheckbox false Boolean When true, a checkbox is displayed next to each item.
filter false Boolean Displays an input filter for the list.
filterMatchMode null String Match mode for filtering, valid values are startsWith (default), contains, endsWith and custom.
filterFunction null String Client side function to use in custom filterMatchMode.
caseSensitive false Boolean Defines if filtering would be case sensitive.
scrollHeight null Integer Defines the height of the scrollable area
converter null Converter/String An 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

Getting Started With SelectManyMenu

selectManyMenu.xhtml

SelectManyMenu.java

SelectManyButton-Initial-View

SelectManyMenu – Custom Content

It’s possible for you to write in your own custom content for every single item. By providing whatever you want of Primefaces/jsf components that enclosed within SelectManyMenu open/end Tags, you can provide your own custom content. Following below sample shows you the same used example with a different images.

selectManyMenu.xhtml

SelectManyMenu-Custom-Content-View

SelectManyMenu – Filtering

You can make use of filter functionality in SelectManyMenu same as the same usage by SelectCheckboxMenu.

SelectOneButton Basic Info

SelectOneButton is an input component to do a single select.

Tag SelectOneButton
Component Class org.primefaces.component.selectonebutton.SelectOneButton
Component Type org.primefaces.component.SelectOneButton
Component Family org.primefaces.component
Renderer Type org.primefaces.component.SelectOneButtonRenderer
Renderer Class org.primefaces.component.selectonebutton.SelectOneButtonRenderer

SelectOneButton Attributes

Name Default Type Description
id null String Unique identifier of the component
rendered true Boolean Boolean value to specify the rendering of the component, when set to false component will not be rendered.
binding null Object An el expression that maps to a server side UIComponent instance in a backing bean
value null Object Value of the component referring to a List.
immediate false Boolean When set true, process validations logic is executed at apply request values phase for this component.
required false Boolean Marks component as required
validator null MethodExpr A method expression that refers to a method validationg the input
valueChangeListener null MethodExpr A method expression that refers to a method for handling a valuechangeevent
requiredMessage null String Message to be displayed when required field validation fails.
converterMessage null String Message to be displayed when conversion fails.
validatorMessage null String Message to be displayed when validation fields.
widgetVar null String Name of the client side widget.
disabled false Boolean Disables the component.
label null String User presentable name.
onchange null String Callback to execute on value change.
style null String Inline style of the component.
styleClass null String Style class of the container.
converter null Converter/St ring An 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

Getting Started With SelectOneButton

selectOneButton.xhtml

SelectOneButton.java

SelectOneListbox Basic Info

SelectOneListbox is an extended version of the standard selectOneListbox component.

Tag SelectOneListbox
Component Class org.primefaces.component.selectonelistbox.SelectOneListbox
Component Type org.primefaces.component.SelectOneListbox
Component Family org.primefaces.component
Renderer Type org.primefaces.component.SelectOneListboxRenderer
Renderer Class org.primefaces.component.selectonelistbox.SelectOneListBoxRenderer

SelectOneListbox Attributes

Name Default Type Description
id null String Unique identifier of the component
rendered true Boolean Boolean value to specify the rendering of the component, when set to false component will not be rendered.
binding null Object An el expression that maps to a server side UIComponent instance in a backing bean
value null Object Value of the component referring to a List.
converter null Converter/ String An 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
immediate false Boolean When set true, process validations logic is executed at apply request values phase for this component.
required false Boolean Marks component as required
validator null MethodExpr A method expression that refers to a method validationg the input
valueChangeListener null MethodExpr A method expression that refers to a method for handling a valuechangeevent
requiredMessage null String Message to be displayed when required field validation fails.
converterMessage null String Message to be displayed when conversion fails.
validatorMessage null String Message to be displayed when validation fields.
widgetVar null String Name of the client side widget.
disabled false Boolean Disables the component.
label null String User presentable name.
onchange null String Callback to execute on value change.
onclick null String Callback for click event.
ondblclick null String Callback for dblclick event.
style null String Inline style of the component.
styleClass null String Style class of the container.
tabindex null String Position of the input element in the tabbing order.
value null String Name of iterator to be used in custom content display.
var null String Name of iterator to be used in custom content display.
filter false Boolean Displays an input filter for the list.
filterMatchMode null String Match mode for filtering, valid values are startsWith (default), contains, endsWith and custom.
filterFunction null String Client side function to use in custom filterMatchMode.
caseSensitive false Boolean Defines if filtering would be case sensitive.
scrollHeight null Integer Defines the height of the scrollable area.

Getting Started With SelectOneListbox

selectOneListbox.xhtml

SelectOneListbox.java

SelectManyCheckbox-Initial-View

SelectOneMenu Basic Info

SelectOneMenu is an extended version of the standard SelectOneMenu.

Tag SelectOneMenu
Component Class org.primefaces.component.selectonemenu.SelectOneMenu
Component Type org.primefaces.component.SelectOneMenu
Component Family org.primefaces.component
Renderer Type org.primefaces.component.SelectOneMenuRenderer
Renderer Class org.primefaces.component.selectonemenu.SelectOneMenuRenderer

SelectOneMenu Attributes

onchangenullStringClient side callback to execute on value change.

Name Default Type Description
id null String Unique identifier of the component
rendered true Boolean Boolean value to specify the rendering of the component, when set to false component will not be rendered.
binding null Object An el expression that maps to a server side UIComponent instance in a backing bean
value null Object Value of the component.
converter null Converter/ String An 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
immediate 0 Boolean When set true, process validations logic is executed at apply request values phase for this component.
required 0 Boolean Marks component as required
validator null MethodExpr A method expression that refers to a method validationg the input
valueChangeListener null MethodExpr A method expression that refers to a method for handling a valuechangeevent
requiredMessage null String Message to be displayed when required field validation fails.
converterMessage null String Message to be displayed when conversion fails.
validatorMessage null String Message to be displayed when validation fields.
widgetVar null String Name of the client side widget.
effect blind String Name of the toggle animation.
effectSpeed 400 Integer Duration of toggle animation in milliseconds.
disabled false Boolean Disables the component.
label null String User presentable name.
onkeyup null String Client side callback to execute on keyup.
onkeydown null String Client side callback to execute on keydown.
style null String Inline style of the component.
styleClass null String Style class of the container.
var null String Name of the item iterator.
height auto Integer Height of the overlay.
tabindex null String Tabindex of the input.
editable false Boolean When true, input becomes editable.
filter false Boolean Renders an input field as a filter.
filterMatchMode starts With String Match mode for filtering, valid values are startsWith, contains, endsWith and custom.
filterFunction null String Client side function to use in custom filtering.
caseSensitive false Boolean Defines if filtering would be case sensitive.
maxlength null Integer Number of maximum characters allowed in editable selectOneMenu.
appendTo null String Appends the overlay to the element defined by search expression. Defaults to document body.

Getting Started With SelectOneMenu

selectOneMenu.xhtml

SelectOneMenu.java

SelectOneMenu-Register-View-1024x129

SelectOneRadio Basic Info

Tag SelectOneRadio
Component Class org.primefaces.component.selectoneradio.SelectOneRadio
Component Type org.primefaces.component.SelectOneRadio
Component Family org.primefaces.component
Renderer Type org.primefaces.component.SelectOneRadioRenderer
Renderer Class org.primefaces.component.selectoneradio.SelectOneRadioRenderer

SelectOneRadio Attributes

Name Default Type Description
id null String Unique identifier of the component
rendered true Boolean Boolean value to specify the rendering of the component, when set to false component will not be rendered.
binding null Object An el expression that maps to a server side UIComponent instance in a backing bean
value null Object Value of the component referring to a List.
converter null Converter/ String An 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
immediate 0 Boolean When set true, process validations logic is executed at apply request values phase for this component.
required 0 Boolean Marks component as required
validator null MethodExpr A method expression that refers to a method validationg the input
valueChangeListener null MethodExpr A method expression that refers to a method for handling a valuechangeevent
requiredMessage null String Message to be displayed when required field validation fails.
converterMessage null String Message to be displayed when conversion fails.
validatorMessage null String Message to be displayed when validation fields.
widgetVar null String Name of the client side widget.
disabled false Boolean Disables the component.
label null String User presentable name.
layout line Direction String Layout of the radiobuttons, valid values are lineDirection, pageDirection, custom and grid.
columns 0 Integer Number of columns in grid layout.
onchange null String Callback to execute on value change.
style null String Inline style of the component.
styleClass null String Style class of the container.
tabindex null String Specifies the tab order of element in tab navigation.
plain false Boolean Plain mode displays radiobuttons using native browser rendering instead of themes.

Getting Started With SelectOneRadio

SelectOneRadio usage is same as the using of SelectOneMenu with one difference is that a set of radio controls are rendered rather using of menu control.

Summary

All of Selective components are collected and explored in a one location. A detailed explanations, figures and examples are provided for all of them. Contribute us by commenting below and find downloaded source code.

By admin

Leave a Reply

%d bloggers like this: