function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
parkerAPTparkerAPT 

Correction to Documentation: <apex: ComponentBody>

There is a small error in the documentation for the <apex:componentBody> tag.

 

The example code for the custom component is the following:

 

<!-- Component: myaccounts-->
<apex:component controller="myAccountsCon">
<apex:attribute name="var" type="String" description="The variable to represent a single account in the iteration."/>
<apex:repeat var="componentAccount" value="{!accounts}">
<apex:componentBody >
<apex:variable var="a" value="{!componentAccount}"/>
<apex:outputPanel style="border:1px solid black;" layout="block">
{!componentAccount.name}
</apex:outputPanel>
</apex:componentBody>
</apex:repeat>
</apex:component>

 

The entire example works because you use "a.name" in apex:ComponentBody even though you should be able to pass in and use any variable name you'd like.  The lines that need to be changed to make this work are:

 

<apex:componentBody >
<apex:variable var="a" value="{!componentAccount}"/>

 

I've made the changes to make the componentBody after the variable tag and changed the variable name to that passed in via the "var" attribute in the component:

 

 

<apex:component controller="myAccountsCon">
<apex:attribute name="var" type="String"
description="The variable to represent a single account in the iteration." />
<apex:repeat var="componentAccount" value="{!accounts}">
<apex:variable var="{!var}" value="{!componentAccount}" />
<apex:componentBody >
<apex:outputPanel style="border:1px solid black;" layout="block">
{!componentAccount.name}
</apex:outputPanel>
</apex:componentBody>
</apex:repeat>
</apex:component>

 

 

Hope this helps anyone trying to use componentBody within custom components!

 

ps- Can you have components with custom Facets?

 

Parker

 

 

 

 

 

 

mtbclimbermtbclimber

Thanks Parker. We'll get this fixed.

 

You can't create custom facets yet but it's on the roadmap.  Not sure if there is an idea out there yet for it yet but would help.

 

Thanks again,