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
ssfdcssfdc 

Supplying String [] param to a component

Hi,

     I'm wondering if anyone knows if there's a way to supply a String[] as a list of strings as a Param into a component,

 

Take this for an example:

VF page

<c:myComp dataPanel="STRING [] I WANT TO SUPPLY" />

 

COMPONENT

<apex:attribute name="dataPanel" description="String[]" type="String[]" required="false"/>

 

So far the only way I can supply a String[] is to create one in a controller and assisng it to dataPanel={!strArrayInController}

 

I find this messy if someone is using this compoent and only need supply a few strings in say Comma seperated format I would have imagined somehting like this exists:

 

<c:myComp dataPanel="new String[] {'one','two','three'}" />

 

 

Any idea's?

 

Thanks

 

ibtesamibtesam

One workaround would be define as many different attributes you want to pass in your component, then assign each attribute some value!

 

like <c:mycomponent var1=" " var2=" " var3= " " />

 

and inside component

 

<apex:attribute name="var1" />

 <apex:attribute name="var2" />

 <apex:attribute name="var3" />

ssfdcssfdc

Thanks ibtesam,

                         I thought of that but the problem is I do not know the amount of strings that may need to be supplied, a workaround I was thinking of was just to supply a comma sperated string then seperate them in my JS but this will have adverse effects down the line for me so I thought id see if this way was possible first.

sfdcfoxsfdcfox

You might making it a String (like you thought), and have it be JSON encoded. JSON is easily parsed in JavaScript and transfers well. The only downside is the additional escaping you'll have to do to get the JSON string to go into the parameter. Ditto for XML encoding, URL encoding, or even just using an uncommon separator (instead of commas, maybe a pipe "|" or caret "^").