salesforce
  1. salesforce-apex-inputcheckbox-component

apex:inputCheckbox Component

The apex:inputCheckbox component is a Visualforce component used to create a checkbox input field. This component allows users to select a value from a list of options.

Syntax

The syntax for apex:inputCheckbox component is:

<apex:inputCheckbox value="{!value}" />

Where value is the boolean variable that will be set to true if the checkbox is checked or false if it is unchecked.

Example

Consider the following example:

<apex:page>
    <apex:form id="form">
        <apex:inputCheckbox value="{!isChecked}" label="Check for Yes" />
        <apex:commandButton value="Submit" rerender="output" action="{!submit}" />
    </apex:form>
    <apex:outputPanel id="output">
        <apex:outputText value="The value of the checkbox is {!IF(isChecked, 'checked', 'unchecked')}" rendered="{!NOT(ISNULL(isChecked))}" />
    </apex:outputPanel>
</apex:page>

In the above code, isChecked is a boolean variable that will be set to true or false based on whether the checkbox is checked or unchecked.

Explanation

When the user checks or unchecks the checkbox, the value of the isChecked variable is updated accordingly. When the user clicks the Submit button, the submit action is called, which can be defined in the controller. In this action, you can use the isChecked variable to perform various operations based on whether the checkbox is checked or unchecked.

The apex:outputText component is used to display the value of the isChecked variable on the page. The rendered attribute is used to control whether or not the output text should be displayed based on the value of isChecked.

Use

The apex:inputCheckbox component can be used to create checkbox input fields on Visualforce pages. These input fields can be used to capture user input and perform various operations based on the user's selection.

Important Points

  • The value attribute of the apex:inputCheckbox component should be bound to a boolean variable in the controller.
  • The label attribute can be used to specify the label for the checkbox input field.
  • The rendered attribute of the apex:outputText component can be used to control whether or not the output text should be displayed based on the value of the isChecked variable.

Summary

The apex:inputCheckbox component is a Visualforce component used to create a checkbox input field. The value attribute should be bound to a boolean variable in the controller. The label attribute can be used to specify the label for the checkbox input field. The rendered attribute of the apex:outputText component can be used to control whether or not the output text should be displayed based on the value of the isChecked variable. The apex:inputCheckbox component can be used to capture and process user input in Visualforce pages.

Published on: