apex:input Component
The apex:input
component is a Visualforce component in Salesforce used to create input fields in forms. This component can be used to create various types of input fields such as text fields, picklists, checkboxes, radio buttons, etc.
Syntax
The syntax for the apex:input
component is as follows:
<apex:input type="{!type}"
value="{!binding}"
id="{!unique-id}"
required="{!is-required}"
rendered="{!is-rendered}"
size="{!length}"
label="{!label}" />
Here,
type
: The type of input field to be created. Valid values includetext
,password
,checkbox
,radio
,hidden
,file
,date
, etc.value
: The value binding for the input field. This can be a variable of the controller or a component.id
: A unique ID for the input field.required
: A Boolean value that specifies whether the input field is required.rendered
: A Boolean value that specifies whether the input field is rendered.size
: The size of the input field.label
: The label for the input field.
Example
Consider the following example for creating a simple text field using the apex:input
component:
<apex:page>
<apex:form>
<apex:pageBlock>
<apex:pageBlockSection>
<apex:inputLabel value="Name" for="name" />
<apex:inputText id="name" value="{!name}" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Here, an input label with the text "Name" is created using the apex:inputLabel
component, and an input field of type text
with an ID of "name" is created using the apex:inputText
component.
Output
The above example creates a simple text field with a label "Name" in a Visualforce page.
Explanation
The apex:input
component is used to create input fields for forms in Visualforce pages. In the above example, a text field with a label "Name" is created using the apex:inputText
and apex:inputLabel
components.
Use
The apex:input
component can be used to create various types of input fields such as text fields, picklists, checkboxes, radio buttons, etc. in forms. These input fields can be used to collect data from users or display data from the controller.
Important Points
- Always use the
for
attribute in theapex:inputLabel
component to associate the label with the input field. - The
value
attribute in theapex:input
component is used to bind the input field to a variable in the controller. - The
id
attribute in theapex:input
component is used to uniquely identify the input field. - The
required
attribute in theapex:input
component is used to require input for the given field.
Summary
The apex:input
component in Visualforce is used to create input fields for forms. It can be used to create various types of input fields such as text fields, picklists, checkboxes, radio buttons, etc. It is important to properly bind the input fields to a variable in the controller and use the apex:inputLabel
component to associate the label with the input field.