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
hamayoun65hamayoun65 

Dynamic Visualforce Components and Merge Fields

Can the new Dynamic Visualforce Components be used to generate an outputText tag with merge fields, such that the merge fields are resolved when the page is displayed?  Something like this.

 

<apex:page standardController="Account" extensions="dynamicSample">
Name: <apex:dynamicComponent componentValue="{!dynamicName}"/> 
</apex:page>

 

public class dynamicSample {
public Component.Apex.OutputText getName () {
String x = new Component.Apex.OutputText;
x.value = "{!Account.Name}" ;
return x ;

aballardaballard

Yes, but to set an expression on a dynamic component attribute you use

x.expressions.value="{!Account.name}"

hamayoun65hamayoun65

What if there are multiple merge fields?  Something like "Your first name is {!Account.FirstName} and your surname is {!Account.Surname}" ?  Any way of doing that?  

 

TIA

hamayoun65hamayoun65

To answer trhe question, this is doable.  You can say:

 

x.expressions.value = 'Your first name is {!Account.FirstName} and your surname is {!Account.Surname}' ; 

 

and it will display correctly in the VF page.  However, I discovered a bug in the SFDC implementation of this (which I notified SFDC about).  If the last char of x.expressions.value is a period (.), then it causes an internal error.  So this will cause that to happen:

 

x.expressions.value = 'Your first name is {!Account.FirstName} and your surname is {!Account.Surname}.' ; // Note period at end

 

 

 

 

stayal1.2953349221005618E12stayal1.2953349221005618E12

ApeX Page:-  

 

<apex:page controller="examples15" >
<apex:form >
<apex:dynamicComponent componentValue="{!outtext}"/>
<apex:dynamicComponent componentValue="{!cmdbutton}"/>
</apex:form>
</apex:page>

 

 

Apex Controller:- 

 

public class examples15
{

public Component.Apex.OutputText getOuttext()
{

Component.Apex.OutputText outText = new Component.Apex.OutputText();
outText.value = 'Some dynamic output text.';

return outText;
}

public Component.Apex.CommandButton getcmdbutton()
{

Component.Apex.CommandButton cmdbutton = new Component.Apex.CommandButton();
cmdbutton.value = 'Click';
return cmdbutton;
}
}

 

 

Kindly Check it and Send Response.


aballardaballard

Are you haviong a problem with it?