So I am trying to iterate through a list of custom objects and print out the information that I need. The issue is that with this object I cannot guarantee where the information I need is so I made a method in my controller that given the object, it will return a string with the information that I want to print. My problem is trying to combine the repeat, outputText and param components.
Here is the visualforce chunk that I have:
<apex:repeat value="{!relationships}" var="relation">
<apex:outputText value="{!getOutput}">
<apex:param value="relation" assignTo="{!relationshipToPrint}" />
</apex:outputText>
</apex:repeat>
and here are the snippits of my apex controller code that are relevant:
public List<Relationship_Detail__c> relationships { get; set; }
public Id recordID { get;set; }
public Relationship_Detail__c relationshipToPrint { get;set; }
public String getOutput(){
String result = '';
boolean isPrimary = (relationshipToPrint.First_Contact__c == recordID
|| relationshipToPrint.First_Account__c == recordID);
if(isPrimary){
if(relationshipToPrint.Second_Contact__c != null){
result = relationshipToPrint.Second_Contact__r.Name;
}
else{
result = relationshipToPrint.Second_Account__r.Name;
}
result = result + ' (' + relationshipToPrint.Second_Relationship_Type__r.Name + ')';
}
else{
if(relationshipToPrint.First_Contact__c != null){
result = relationshipToPrint.First_Contact__r.Name;
}
else{
result = relationshipToPrint.First_Account__r.Name;
}
result = result + ' (' + relationshipToPrint.First_Relationship_Type__r.Name + ')';
}
return result;
}
The function works correctly, however, I am having difficulty passing the current custom object into the relationshipToPrint variable so that it can be used in the method. I hope that this makes some sense and please feel free to ask questions.
value="relation"
tovalue="{!relation}"
so that you are reference the loopvar
. Alsovalue="{!getOutput}"
should probably bevalue="{!output}"
as the "get" part of the name is implied.