You need to sign in to do that
Don't have an account?

Dynamically create page sections from custom object
Hello,
I have added a custom HTML component in the home page with a reference to a visualforce page I have. The FrontPageNews object will contain the info I want to show in the page blocks. It needs to be one page block per record.
I need to iterate over the records and for each one, create a page block with the block title taken from a field in the custom object, and the page section has an outputText tag that would also get the text from a field in the custom object.
How can this be achieved? I have no clue how to iterate over objects in visualforce. Much lessdynamically create pageblocks and pageBlockSections.
Hi,
In your VF code:
the attribute value in apex:repeat tag is not returning any value. Its null so no pageblocksection is getting created.
I suggest you create a method in extension class which will pass list of FrontPageNewsItem__c.
Using std controller will not automatically send you list of records of that object. You will need a method to explicitly pass it.
If it works as suggested, then please accept it as solution!!!!
All Answers
Hi,
Try using <apex:repeat> tag in which add the pageblock thing
here Item is list of records of an object.
Let me know if you have any issues
Hello,
Thank you for that piece of code it seems like the right solution, yet Im thinking that I might still be doing something wrong since when I save the page with teh code below, it refreshes empty, the pageblock is created but the pagesections are not, yet if I replace the {!item} variables with regular text it works. PLease let me know if you can spot my mistake.
<apex:page sidebar="False" showHeader="False" standardcontroller="FrontPageNewsItem__c" >
<apex:pageBlock >
<apex:repeat value="{!FrontPageNewsItem__c}" var="item">
<apex:pageBlockSection title="{!item.Name}" >
<apex:outputText value="{!item.Body_Text__c}" > </apex:outputText> </apex:pageBlockSection>
</apex:repeat>
</apex:pageBlock>
</apex:page>
Thank you!
Hi,
In your VF code:
the attribute value in apex:repeat tag is not returning any value. Its null so no pageblocksection is getting created.
I suggest you create a method in extension class which will pass list of FrontPageNewsItem__c.
Using std controller will not automatically send you list of records of that object. You will need a method to explicitly pass it.
If it works as suggested, then please accept it as solution!!!!