I'm running into an issue where a custom component inside an apex:repeat isn't updating the component controller binding.
Here's where the component is called:'
<apex:repeat value="{!providersMatchingAll}" var="match">
<c:providerblock record="{!match.Provider__r}"/>
</apex:repeat>
Here is a trimmed down component definition:
<apex:component controller="ProviderBlockDetailController">
<apex:attribute name="record" type="Account" description="The provider account to display." assignTo="{!provider}" required="true"></apex:attribute>
<a name="{!record.Id}"/>
<c:panel title="{!record.Name}" type="primary" styleclass="providerblock">
<p>Mon-Fri {!earliestWeekdayStart}-{!latestWeekdayEnd} <br/>
Sat-Sun {!earliestWeekendStart}-{!latestWeekendEnd}</p>
<p><apex:outputField value="{!record.Yearly_Schedule__c}"/><apex:outputText value=" -- " rendered="{!NOT(ISBLANK(record.Schedules_And_Programs__c))}"/><apex:outputField value="{!record.Schedules_and_Programs__c}"/></p>
</c:panel>
</apex:component>
and here is the detail block controller:
public with sharing class ProviderBlockDetailController {
public Account provider {get;set;}
public String getEarliestWeekdayStart() {
try {
List<DateTime> startTimes = new List<DateTime> {
getDateTimeFromTimePicklist(provider.Schedule_Monday_Earliest_Start__c),
getDateTimeFromTimePicklist(provider.Schedule_Tuesday_Earliest_Start__c),
getDateTimeFromTimePicklist(provider.Schedule_Wednesday_Earliest_Start__c),
getDateTimeFromTimePicklist(provider.Schedule_Thursday_Earliest_Start__c),
getDateTimeFromTimePicklist(provider.Schedule_Friday_Earliest_Start__c)
};
startTimes.sort();
return startTimes[0].format('h:mm a');
} catch(Exception e) {
return 'Unknown and not migrated';
}
}
public String getLatestWeekdayEnd() {
try {
List<DateTime> endTimes = new List<DateTime> {
getDateTimeFromTimePicklist(provider.Schedule_Monday_Latest_End__c),
getDateTimeFromTimePicklist(provider.Schedule_Tuesday_Latest_End__c),
getDateTimeFromTimePicklist(provider.Schedule_Wednesday_Latest_End__c),
getDateTimeFromTimePicklist(provider.Schedule_Thursday_Latest_End__c),
getDateTimeFromTimePicklist(provider.Schedule_Friday_Latest_End__c)
};
endTimes.sort();
return endTimes[4].format('h:mm a');
} catch(Exception e) {
return 'Unknown and not migrated';
}
}
public String getLatestWeekendEnd() {
try {
List<DateTime> endTimes = new List<DateTime> {
getDateTimeFromTimePicklist(provider.Schedule_Sunday_Latest_End__c),
getDateTimeFromTimePicklist(provider.Schedule_Sunday_Latest_End__c)
};
endTimes.sort();
return endTimes[1].format('h:mm a');
} catch(Exception e) {
return 'Unknown and not migrated';
}
}
public String getEarliestWeekendStart() {
try {
List<DateTime> endTimes = new List<DateTime> {
getDateTimeFromTimePicklist(provider.Schedule_Saturday_Earliest_Start__c),
getDateTimeFromTimePicklist(provider.Schedule_Sunday_Earliest_Start__c)
};
endTimes.sort();
return endTimes[0].format('h:mm a');
} catch(Exception e) {
return 'Unknown and not migrated';
}
}
public DateTime getDateTimeFromTimePicklist(String picklistValue) {
return DateTime.parse('1/1/2015 '+picklistValue);
}
}
For every display of the component, the earliestWeekdayStart/earliestWeekdayEnd pair show the value of the first record in the repeat set, instead of the record they are on.
If I call the component outside of an apex:repeat
<c:providerblock record="{!providersMatchingAll[0].Provider__r}"/>
<c:providerblock record="{!providersMatchingAll[1].Provider__r}"/>
it behaves as expected.
