0

I am trying to figure out how to use the value of a custom field (textfield or textarea) as the values for an apex:repeat in a visualforce page.

For example, I have a custom field, issues__c, that has the following value:

Issue1, Issue2, Issue3

Alternately the values could be stored with newlines as:

Issue1
Issue2
Issue3

I want pass each of these entries as the value for an apex:repeat, which in turn would create html links to each of the above values stored in the text field.

I assume that I will need to write a controller to accomplish this, but my understanding of writing controller extensions is very limited at the moment.

The bits I am missing are: How do I pass the value of issues__c to the controller? How do I return each line or entry in issues__c back to the apex:repeat in the VF page?

Or is there an easier way?

1
1

Here is an example of how I would do it. You will have to adapt it for your use.

VF Page:

<apex:page standardController="[OBJECT API NAME]" extensions="[OBJECTNAME]_ExtensionController">

  <apex:repeat value="{!splitString}" var="s">
      I am repeating. {!s} is the current value. <br />
  </apex:repeat>

</apex:page>

Extension:

public with sharing class [OBJECTNAME]_ExtensionController {

    public List<string> splitString {get;set;}

    public AccountExtensionController(ApexPages.StandardController controller)
    {
        controller.addFields(new List<string>{'Issues__c'});
        [OBJECT API NAME] record = ([OBJECT API NAME])controller.getRecord();

        splitString = new List<string>();

        if(!String.IsBlank(record.Issues__c))
            splitString = record.Issues__c.split(',');
    }

}

Good luck!

Luis Luciani

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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