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
patrospatros 

Two instances of a component on one page - only one seems to process?

I wrote a basic component that renders data in an HTML tag, which you can pass as an attribute on the component. Ultimately, this will we be much more sophisticated, but I can't even get this working when I put two of the same component on one Visualforce page. The first component renders, but the second appears to be ignored. We're working on a lightweight CMS for Visualforce, so it would not be unrealistic to have multiple instances of the same component rendered multiple "content blocks" into one final page.

 

 

COMPONENT:

 

<apex:component controller="CTRL_COMP_cms_content">
<apex:attribute assignTo="{!wrap}" name="wrap" description="The HTML tag to wrap this component with." type="String" required="false" />

<apex:attribute assignTo="{!text}" name="text" description="The text to put in the tag." type="String" required="false" />

<apex:outputText value="{!output}" escape="false" />
</apex:component>

 

CONTROLLER:

 

public class CTRL_COMP_cms_content {

 

public String wrap {
get {
if(wrap == null) wrap = '';
return wrap;
}
set;
}

public String text {
get {
if(text == null) text = '';
return text;
}
set;
}

public String output {
get {
if(wrap == '') return text;

return '<' + wrap + '>' + text + '</' + wrap + '>';
}
}

public CTRL_COMP_cms_content() {}

}

 

PAGE WITH COMPONENTS:

 

<apex:page id="the-page">
<c:cms_content id="text1" text="First Text" wrap="div"></c:cms_content>
<c:cms_content id="text2" text="Second Text" wrap="div"></c:cms_content>
</apex:page>

 

FINAL RENDERED HTML OUTPUT:

 

<span id="the-page:text1"><div>First Text</div></span>

<span id="the-page:text2"></span>

 

The final HTML output includes the results from the first component and renders the <span> for the second component, but the contents of the second component are never rendered.

 

Help!

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
dchasmandchasman

I copied you example verbatim into a Summer '09 developer edition org and the following correct output was generated (BTW we did fix a couple of assignTo related issues in Summer '09):

 

 

<span id="the-page:text1"><div>First Text</div></span><span id="the-page:text2"><div>Second Text</div></span>

 

 

 

All Answers

TehNrdTehNrd

This may be related to the same issue I encountered here: http://community.salesforce.com/sforce/board/message?board.id=Visualforce&thread.id=9170 which, from what I can tell, has not been patched yet.

 

I would encourage you to start the process of opening a support case if you can.

 

 

dchasmandchasman

I copied you example verbatim into a Summer '09 developer edition org and the following correct output was generated (BTW we did fix a couple of assignTo related issues in Summer '09):

 

 

<span id="the-page:text1"><div>First Text</div></span><span id="the-page:text2"><div>Second Text</div></span>

 

 

 

This was selected as the best answer
patrospatros

Thanks Doug - I just confirmed that it is working in my dev org running on NA6 (which was upgraded to Summer 09 on June 5). Awesome!