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
J&A-DevJ&A-Dev 

Passing a complex type as value for the repeat tag

I created a custom component with the following 2 attributes:

 

<apex:component > <apex:attribute name="zoneSales" description="Zone Sales." type="String" required="true"/> <apex:attribute name="zoneLabel" description="Zone Label." type="String" required="true"/> <apex:pageBlockSection id="PB_JNLD_Zone1P" title="{!zoneLabel}" collapsible="false"> <apex:pageBlockTable value="{!zoneSales}" var="zcm"> <apex:column value="{!zoneSales}" headerValue="Total-JNLD"/> </apex:pageBlockTable> </apex:pageBlockSection> </apex:component>

 

In my controller, I created an inner class that will contain the 2 attributes:

 

String[] myZoneNumber = new String[]{'Zone 1', 'Zone 2', 'Zone 3', 'Zone 4', 'Zone 5', 'Zone 6', 'Zone 7', 'Zone 8'}; String[] myZoneTotal = new String[]{'$1', '$2', '$3', '$4', '$5', '$6', '$7', '$8'}; public MyZoneObject getInitMyZoneObject() { MyZoneObject mzo = new MyZoneObject(myZoneNumber, myZoneTotal); return mzo; } public class MyZoneObject { public String[] myZoneNumber {get;set;} public String[] myZoneTotal {get;set;} public MyZoneObject(String[] zoneNumber, String[] zoneTotal) { this.myZoneNumber = zoneNumber; this.myZoneTotal = zoneTotal; } }

 

 And finally, here's how I call my component from the VF page:

 

<apex:repeat value="{!InitMyZoneObject}" var="myZoneObj"> <c:ZoneComponent zoneLabel="{!myZoneObj.myZoneNumber}" zoneSales="{!myZoneObj.myZoneTotal}"/> </apex:repeat>

 

What I expecting to happen is for the pageBlockSection to repeat 8 times, which is array size for either attribute. Instead, I'm getting a single pageBlockSection displaying the entire array for both attributes. What I'm not entirely sure is the way I created the inner class "MyZoneObject".

 

Thanks in advance.


 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
J&A-DevJ&A-Dev
Thanks for the suggestion Venkat, but that didn't work. I did figured out what the problem was though: the type of both attributes was fine as String, but I was passing a single instance of my complex object to the repeat tag value. So instead, I modified my the controller code to pass a list of MyZoneObject and the inner class variables and constructor to set strings instead of String[].

All Answers

Venkat PolisettVenkat Polisett

Try changing the type to array and see what happens. 

 

<apex:attribute name="zoneSales" description="Zone Sales." type="String[]" required="true"/>
<apex:attribute name="zoneLabel" description="Zone Label." type="String[]" required="true"/>

 

If it works, please let us know.

 

 

J&A-DevJ&A-Dev
Thanks for the suggestion Venkat, but that didn't work. I did figured out what the problem was though: the type of both attributes was fine as String, but I was passing a single instance of my complex object to the repeat tag value. So instead, I modified my the controller code to pass a list of MyZoneObject and the inner class variables and constructor to set strings instead of String[].
This was selected as the best answer