Visualforce 页面中的 <apex: composition> 组件

17 Mar 2025 | 阅读 2 分钟

<apex: composition> 是另一个重要组件,用于定义页面的一个区域,该区域包含来自第二个模板页面的内容。 模板页面包含一个或多个 <apex: insert> 组件。 <apex: composition> 组件命名关联的模板,并为模板的 <apex: insert> 组件提供一个主体,其中包含匹配的 <apex: define> 组件。 <apex: composition> 组件之外的任何内容都不会呈现。

我们使用此组件从控制器方法获取用户输入,该方法与 sObject 字段上的字段不对应。

<apex: composition> 组件具有以下属性

1. rendered

rendered 是用于呈现组件的字符串类型属性。 但是,rendered 属性不会影响此组件的显示。

语法

2. template

template 是一个 "ApexPages.PageReference" 类型,用于指定用于此组件的模板页面。 apex 页面或 PageReference 的名称用作此属性的值。

语法

让我们看一个例子来了解如何在 Visualforce 页面上使用此组件

ApexCompositionExample.vfp

ApexInsertExample.vfp

输出

apex: composition Component in Visualforce Page