I know there are other questions similar to this but I could not figure out a way to solve my issue.
In my Visualforce page, I have a repeater – I need to call the controller method to get data from another object using ID from the repeater object.
Visualforce:
<apex:repeat var="a" value="{!articles}">
<!-- this is how I am setting the ArticleId variable in apex ---NOT WORKING -->
<apex:param name="ArticleId" value="{!(a.Article_Id__c)}" assignTo="{!ArticleId}"/>
<!setFaqAnswer> <!-- Calling the method -->
<div class="divQuestion" "> {!a.Title__c} </div>
<div class="divSummary" > {!a.Summary__c} </div>
<div class="divAnswer" > {!faq.Answer__c} </div> <!-- <-- Using the faq object here -->
</apex:repeat>
Controller:
public FAQ faq {get;private set;}
public Id ArticleId {
get; set;
}
public void setFaqAnswer {
get {
try {
faq = [select Answer__c, Links__c from FAQ__kav where KnowledgeArticleId = :ArticleId and IsVisibleInPkb = true];
}
catch (QueryException qe) {
System.debug('@@@@' + qe); // <-- Not being able to view this in setup>log>debug logs
}
}
}
Best Answer
Build your data structure in your controller class using a wrapper (AKA decorator) class such as this:
And then make your repeater loop round a list of the ArticelWrapper classes.
You can't use Visualforce repeaters in the same way you use for loops in apex - do the apex bit first, then use the repeater purely for generating the user interface.