Newer Version Available
apex:componentBody
This tag allows a custom component author to define a location where a user can insert content into the custom component. This is especially useful for generating custom iteration components. This component is valid only within an <apex:component> tag, and only a single definition per custom component is allowed.
Simple Example
1<!-- Page: -->
2<apex:page>
3 <apex:outputText value="(page) This is before the custom component"/><br/>
4 <c:bodyExample>
5 <apex:outputText value="(page) This is between the custom component" /> <br/>
6 </c:bodyExample>
7 <apex:outputText value="(page) This is after the custom component"/><br/>
8</apex:page>
9
10<!-- Component: bodyExample -->
11<apex:component>
12 <apex:outputText value="First custom component output" /> <br/>
13 <apex:componentBody />
14 <apex:outputText value="Second custom component output" /><br/>
15</apex:component>Advanced Example
1<!-- Page: -->
2<apex:page >
3 <c:myaccounts var="a">
4 <apex:panelGrid columns="2" border="1">
5 <apex:outputText value="{!a.name}"/>
6 <apex:panelGroup >
7 <apex:panelGrid columns="1">
8 <apex:outputText value="{!a.billingstreet}"/>
9 <apex:panelGroup >
10 <apex:outputText value="{!a.billingCity},
11 {!a.billingState} {!a.billingpostalcode}"/>
12 </apex:panelGroup>
13 </apex:panelGrid>
14 </apex:panelGroup>
15 </apex:panelGrid>
16 </c:myaccounts>
17</apex:page>
18
19<!-- Component: myaccounts-->
20<apex:component controller="myAccountsCon">
21 <apex:attribute name="var" type="String" description="The variable to represent
22 a single account in the iteration."/>
23 <apex:repeat var="componentAccount" value="{!accounts}">
24 <apex:componentBody >
25 <apex:variable var="{!var}" value="{!componentAccount}"/>
26 </apex:componentBody>
27 </apex:repeat>
28</apex:component>
29
30/*** Controller ***/
31public class myAccountsCon {
32
33public List<Account> accounts {
34 get {
35 accounts = [select name, billingcity, billingstate, billingstreet, billingpostalcode
36 from account where ownerid = :userinfo.getuserid()];
37
38 return accounts;
39 }
40 set;
41 }
42}The example above renders the following HTML:
1<table width="100%" cellspacing="0" cellpadding="0" border="0" id="bodyTable" class="outer">
2 <!-- Start page content table -->
3 <tbody><tr><td id="bodyCell" class="oRight">
4 <!-- Start page content -->
5 <a name="skiplink"><img width="1" height="1"
6 title="Content Starts Here" class="skiplink"
7 alt="Content Starts Here" src="/s.gif"/></a><span id="j_id0:j_id1">
8 <table border="1">
9 <tbody>
10 <tr>
11 <td>sForce</td>
12 <td><table>
13 <tbody>
14 <tr>
15 <td>The Land's Mark @ One Market</td>
16 </tr>
17 <tr>
18 <td>San Francisco, CA 94087</td>
19 </tr>
20 </tbody>
21 </table>
22 </td>
23 </tr>
24 </tbody>
25 </table>
26 <table border="1">
27 <tbody>
28 <tr>
29 <td>University U</td>
30 <td>
31 <table>
32 <tbody>
33 <tr>
34 <td>888 N Euclid
35 Hallis Center, Room 501
36 Tucson, AZ 85721
37 United States</td>
38 </tr>
39 <tr>
40 <td>Tucson, AZ </td>
41 </tr>
42 </tbody>
43 </table>
44 </td>
45 </tr>
46 </tbody>
47 </table>
48 </span>
49 </td>
50 </tr>
51 </tbody>
52</table>Attributes
| Attribute Name | Attribute Type | Description | Required? | API Version | Access |
|---|---|---|---|---|---|
| id | String | An identifier that allows the component to be referenced by other components in the page. | 13.0 | global | |
| rendered | Boolean | A Boolean value that specifies whether the component is rendered on the page. If not specified, this value defaults to true. | 13.0 | global |