Editing a Table of Data in a Page
In the last tutorial, you built a table of data. Using <apex:inputField> in the data table columns, you can create a table with editable fields. Using <apex:commandButton> you can save the data you change. Any message (such as Saving) is automatically displayed with the <apex:pageMessages> tag.
The following page creates a page that enables you to edit a series
of Industry types at the same time:
<apex:page standardController="Account" recordSetVar="accounts"
tabstyle="account" sidebar="false">
<apex:form>
<apex:pageBlock >
<apex:pageMessages />
<apex:pageBlockButtons>
<apex:commandButton value="Save" action="{!save}"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!accounts}" var="a">
<apex:column value="{!a.name}"/>
<apex:column headerValue="Industry">
<apex:inputField value="{!a.Industry}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Notice the following about the page markup:
- This page takes advantage of standard set controllers to generate the data for the table. Use the recordSetVar attribute to specify the name of the set of data you want to use. Then, in the <apex:pageBlockTable> value, use the name of that set to populate the table with data.
- The <apex:inputField> tag automatically generates the correct display for the field. In this case, as a drop-down list.
- The page must be enclosed in an <apex:form> tag in order to use the <apex:commandButton> tag. A form specifies a portion of a Visualforce page that users can interact with.
Example of Editing a Table of Data
