代码实现类似Html的表单(Form)
<apex:page sidebar="false" standardController="Account">
<apex:form>
<apex:pageBlock title="Edit Account">
<apex:pageMessages></apex:pageMessages>
<apex:pageBlockSection columns="1">
<apex:inputField value="{!Account.Name}"/>
<apex:inputField value="{!Account.Phone}"/>
<apex:inputField value="{!Account.Industry}"/>
<apex:inputField value="{!Account.AnnualRevenue}"/>
</apex:pageBlockSection>
<apex:pageBlockButtons>
<apex:commandButton action="{!save}" value="Save"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
代码解释:
- sidebar="false"不显示侧边栏,standardController="Account"表示标准控制器(即系统自带的属性,Account类似于系统自带的表)
- 表单必须为<apex:form></apex:form>形式, <apex:inputField > </apex:inputField >类似于html的<input>
- <apex:pageMessages></apex:pageMessages>添加这一句,表示当必填字段没填写时显示错误信息提醒用户
- <apex:pageBlockButtons> </apex:pageBlockButtons>表示按钮,action=""是为需要执行的操作,Value=""即按钮上显示的文字
效果图如下: