Visualforce 拥有近 150 个可在页面上使用的内置组件。
Visualforce 标准组件( Standard Component Reference )引用中列出了这些组件,并记录了它们的属性,包括如何使用组件的示例代码。
示例代码:
<apex:page sidebar="false" showHeader="false">
<h1>Hello World</h1>
</apex:page>
※sidebar 和 showHeader 属性在 Lightning Experience 中无效,并且无法抑制 Lightning Experience 标头。虽然 showHeader 默认值是 true,但是它对 Lightning Experience 无效。
Note that both the sidebar and showHeader attribute have no effect in Lightning Experience, and that there’s no way to suppress the Lightning Experience header. Although the default value of showHeader is true, it has no effect in Lightning Experience.
页面包含一些 Salesforce 样式表,可匹配 Salesforce 选择的字体、大小等。要抑制 Salesforce 的所有输出,同样需要添加 standardStylesheets=“false” 来删除样式。
The page still includes some Salesforce style sheets, which let you match Salesforce choices for fonts, size, and so on. To suppress all Salesforce output, add standardStylesheets=“false” to remove the styles as well.
请求页面时,组件会呈现为 HTML、CSS 或 JavaScript。
是一种结构化的用户界面元素,用于对页面上的相关项目进行分组
是向页面添加结构和层级的另一个组件。显示时,用户可以折叠 < apex:pageBlockSection> 元素以隐藏除节标题以外的所有元素。需要嵌套在 apex:pageBlock 标签内,否则无法使用
<apex:page standardController="Account" recordSetVar="accounts">
<apex:pageBlock >
<apex:repeat value="{! accounts}" var="a">
<ul>
<li>
<apex:outputLink value="{! URLFOR($Action.Account.View,a.Id)}">
{!a.name}
</apex:outputLink>
</li>
</ul>
</apex:repeat>
</apex:pageBlock>
</apex:page>
预览结果:
点击任意link,显示该Account的详细页面
将record的详细信息快速添加到使用标准控制器的页面。该组件显示特定记录详细信息,以及相关记录的列表,例如联系人、个案、业务机会等。
注意,通过这个组件添加到页面的所有内容都使用 Salesforce Classic 样式
< apex:page standardController="Account">
< apex:detail />
使用 < apex:relatedList> 显示与当前记录相关的记录列表。
< apex:page standardController="Account">
< apex:detail relatedList="false"/>
显示个别关联list:在 <apex:detail /> 行的下方,添加以下标记。
以下代码结果将除详细信息外,只显示【联系人】和【业务机会】两个关联list
< apex:page standardController="Account">
< apex:detail relatedList="false"/>
< apex:relatedList list="Contacts"/>
< apex:relatedList list="Opportunities" pageSize="5"/>
6和7组合可以取代< apex:relatedList>
显示记录中的单个字段,本身只输出字段的值。自动适应正在显示字段的数据类型,例如下面示例的货币类型数据,输出类型为货币,而不是上一篇文章看到的科学计数法
<apex:page standardController="Account">
<apex:outputField value="{! Account.Name }"/>
<apex:outputField value="{! Account.Phone }"/>
<apex:outputField value="{! Account.Industry }"/>
<apex:outputField value="{! Account.AnnualRevenue }"/>
</apex:page>
<apex:page standardController="Account">
<apex:pageBlock title="Account Details">
<apex:outputField value="{! Account.Name }"/>
<apex:outputField value="{! Account.Phone }"/>
<apex:outputField value="{! Account.Industry }"/>
<apex:outputField value="{! Account.AnnualRevenue }"/>
</apex:pageBlock>
</apex:page>
< apex:page standardController="Account">
< apex:pageBlock title="Account Details">
< apex:pageBlockSection >
< apex:outputField value="{! Account.Name }"/>
< apex:outputField value="{! Account.Phone }"/>
< apex:outputField value="{! Account.Industry }"/>
< apex:outputField value="{! Account.AnnualRevenue }"/>
迭代组件:可以使用迭代组件在自己的 Visualforce 标记中执行相同的操作。迭代组件处理类似项的集合,而不是单个值。
如下示例中 {!Account.contacts} 是一个表达式,计算结果为客户的联系人列表。可以将此表达式与迭代组件一起使用,以创建包含这些相关联系人详细信息的列表或表格。
< apex:pageBlockTable> :用于生成数据表,并带有平台样式。采用了 Salesforce Classic 样式
value属性设置为前面提到的表达式 {!Account.contacts}。这是 < apex:pageBlockTable> 使用的记录列表。
< apex:pageBlockTable> 将该记录分配给 < apex:pageBlockTable> 的 var 属性中命名的变量(contact)
依次使用表示当前记录的 contact 变量来提取该记录的字段值。通过查找每个字段标签的方式来创建列标题。
<apex:page standardController="Account">
<apex:pageBlock title="Contacts">
<apex:pageBlockTable value="{!Account.contacts}" var="contact">
<apex:column value="{!contact.Name}"/>
<apex:column value="{!contact.Title}"/>
<apex:column value="{!contact.Phone}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
<apex:page standardController="Account">
<h1>Edit Account</h1>
<apex:form>
<apex:inputField value="{! Account.Name }"/>
<apex:commandButton action="{! save }" value="Save" />
</apex:form>
</apex:page>
<apex:page standardController="Account">
<apex:form>
<apex:pageBlock title="Edit Account">
<apex:pageBlockSection>
<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:pageBlockSection>
<apex:pageBlockButtons>
<apex:commandButton action="{! save }" value="Save" />
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
<apex:page standardController="Account">
<apex:form>
<apex:pageBlock title="Edit Account">
<apex:pageMessages/>
<apex:pageBlockSection>
<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:pageBlockSection>
<apex:pageBlockButtons>
<apex:commandButton action="{! save }" value="Save" />
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
<apex:pageBlock title="Contacts">
<apex:pageBlockTable value="{!Account.contacts}" var="contact">
<apex:column>
<apex:outputLink
value="{! URLFOR($Action.Contact.Edit, contact.Id) }">
Edit
</apex:outputLink>
<apex:outputLink
value="{! URLFOR($Action.Contact.Delete, contact.Id) }">
Del
</apex:outputLink>
</apex:column>
<apex:column value="{!contact.Name}"/>
<apex:column value="{!contact.Title}"/>
<apex:column value="{!contact.Phone}"/>
</apex:pageBlockTable>
</apex:pageBlock>
具体示例参照13
具体示例参照13
具体示例参照13
具体示例参照:Salesforce-Visualforce-5.标准列表控制器(Standard List Controllers)
具体示例参照:Salesforce-Visualforce-5.标准列表控制器(Standard List Controllers)
具体示例参照:Salesforce-Visualforce-5.标准列表控制器(Standard List Controllers)
具体示例参照:salesforce-Visualforce-7.自定义控制器(Custom Controllers)
Building a Table of Data in a Page
Create Visualforce Pages
Developer Console Functionality
Developing Visualforce With Your Browser
Displaying Related Lists for Custom Objects
Displaying Field Values with Visualforce
Using the Editor for Visualforce or Apex
Using the Visualforce Component Library
Using Input Components in a Page
Using Standard Controller Actions
Tools for Visualforce Development
Standard Component Reference
Standard Controllers
The Salesforce Extensions for Visual Studio Code
Lightning Platform Tools and Toolkits
Valid Values for the $Action Global Variable