Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have code much like the following:

    <apex:attribute name="fields" type="String[]" />
    <apex:repeat value="{!fields}" var="field">

When this is placed in a page like this:

<c:MyCustomComponent fields="A,B,C">

The output is just A,B,C (a single value). Enclosing the field names with square brackets does not help, nor does using single quotes. Is there a way to pass an array into a component so that apex:repeat will work on it? (I am aware that this could be done through the controller; I am hoping for a solution that preserves the component interface).

share|improve this question
try StringToStringMap construct {!['herp'='derp', 'foo'='bar]} – bigassforce Oct 30 '15 at 14:46
up vote 1 down vote accepted

I've never seen any notation for parameter literal values in VisualForce that can convert to anything but a String, Number, Boolean, or (in this case) a 1-element array. I'd be very (pleasantly) surprised if you could do what you want. You'll need to populate the component attribute using a controller field reference.

share|improve this answer
Your observation that there is no literal notation for arrays in Visualforce is the insight I needed. I'll have to go with the controller approach I guess. Thanks. – Jeff Trull Feb 8 '13 at 16:53

You could use a controller for the component itself.

You can pass the array in as a string, as you're doing and use the assingTo attribute on the component's parameter to pass the value to a property on the controller.

Then just have another method on the controller which returns the list:

public String theValueFromSomewhere {get; set;}

public List<String> GetBits()
  return theValueFromSomewhere.split(',');

You can then use <apex:repeat value="{!Bits}" var="v"> in your component body as you're after.

share|improve this answer
Controller is best way. Option two is StringToStringMap {!['herp'='derp,'foo'='bar']} – bigassforce Oct 30 '15 at 14:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.