0
我想渲染一個visualforce頁面,並在選擇列表中進行更改。我想呈現的數據是表格中的聯繫人姓名。這根據我選擇的銷售地區而變化。基於picklistValues渲染Visualforcepage
控制器
public class PhotoSchedulerController {
public String salesRegionId { get; set; }
public String ContactSalesRegion {get; set;}
public PageReference salesRegionCoveredFilter() {
String contacts = [Select Id, Name, Sales_Regions_Covered__c from Contact where Sales_Regions_Covered__c = '03'].Sales_Regions_Covered__c;
system.debug('sales region:' + contacts);
return null;
}
public List<SelectOption> getSalesRegionsCoveredValues() {
List<SelectOption> options = new List<SelectOption>();
Schema.DescribeFieldResult salesRegion = Contact.Sales_Regions_Covered__c.getDescribe();
List<Schema.PicklistEntry> salesRegions = salesRegion.getPicklistValues();
for (Schema.Picklistentry entry : salesRegions) {
options.add(new SelectOption(entry.getLabel(), entry.getValue()));
}
return options;
}
public List<String> getHeadDays() {
List<String> formattedDays = new List<String>();
List<DateTime> days = new List<DateTime>();
DateTime currentDay = DateTime.now();
for (Integer idx = 0; idx < 28; idx++) {
days.add(currentDay + idx);
system.debug('DAYS :' + days);
}
for (DateTime dt : days) {
String formattedDay = dt.format('E');
formattedDays.add(formattedDay);
}
return formattedDays;
}
public List<String> getHeadDates() {
List<String> formattedDates = new List<String>();
List<Date> dates = new List<Date>();
Date currentDate = system.today();
for (Integer idx = 0; idx < 28; idx++) {
dates.add(currentDate + idx);
}
for (Date dt : dates) {
String formattedDate = dt.format();
formattedDates.add(formattedDate);
}
return formattedDates;
}
// retrieves the row wrapper containing the wrapped case headings
public List<photographerRow> getDataRows() {
List<String> scheduledDates = new List<String>();
photographerRow pRow = new photographerRow();
List<photographerRow> dataRows = new List<photographerRow>();
for (Contact con : getContacts()) {
pRow.photographer = con.Name;
pRow.photographerId = con.Id;
pRow.contacts.add(con);
}
for (Integer idx = 28; idx > 0; idx--) {
pRow.subtotals.add(idx);
}
for (Case c : getCaseInfo()) {
pRow.caseNumber = c.caseNumber;
pRow.cases.add(c);
}
dataRows.add(pRow);
return dataRows;
}
public class photographerRow {
public String photographer {get; set;}
public String photographerId {get; set;}
public String caseNumber {get; set;}
public List<Contact> contacts {get; set;}
public List<Case> cases {get; set;}
public List<Integer> subtotals {get; set;}
public List<Integer> counts {get; set;}
// constructor
public PhotographerRow() {
contacts = new List<Contact>();
subtotals = new List<Integer>();
counts = new List<Integer>();
cases = new List <Case>();
}
}
public List<Contact> getContacts() {
List<Contact>contacts = [Select Id, Name, Sales_Regions_Covered__c from Contact ];
return contacts;
}
public List<Case> getCaseInfo() {
List<String> contactsList = new List<String>();
List<String> formattedDatesList = new List<String>();
for (Contact c : getContacts()) {
contactsList.add(c.Name);
}
List<Date> dates = new List<Date>();
Date currentDate = system.today();
for (Integer idx = 0; idx < 28; idx++) {
dates.add(currentDate + idx);
}
system.debug('Dates List :' + dates);
system.debug('Contact LIst :' + contactsList);
List<Case> cases = [Select id, CaseNumber, Scheduled_Date__c , Account.Owner.Name, Photographer_Contact__r.Name from Case where RecordType.DeveloperName In('Time_Booking', 'Media_Package', 'Photography')
and Scheduled_Date__c = :dates];
system.debug('case queried:' + cases);
return cases;
}
/* public Integer getCaseCount(){
Integer caseCount;
List<AggregateResult> groupedCases = [Select count(casenumber),Scheduled_Date__c, Photographer_Contact__r.Name from Case where RecordType.DeveloperName In('Time_Booking', 'Media_Package', 'Photography') and Scheduled_Date__c!=null group by Photographer_Contact__r.Name,Scheduled_Date__c];
for (AggregateResult ar : groupedCases) {
caseCount = Integer.valueOf(ar.get('expr0'));
}
return caseCount;
}*/
}
<apex:page controller="PhotoSchedulerController" tabstyle="Report" sidebar="false">
<apex:form>
<apex:outputPanel id="dataBlocks">
<apex:sectionHeader title="Field Researcher Schedule for Region" />
<apex:selectList value="{!contactSalesRegion}" size="1" multiselect="false">
<b>Field Researcher Schedule for Region</b>
<apex:selectOptions value=" {!SalesRegionsCoveredValues}"></apex:selectOptions>
<apex:actionSupport event="onchange" action="{!salesRegionCoveredFilter}" reRender="dataBlock">
<apex:param name="salesRegionId" assignTo="{!salesRegionId}" value="{!SalesRegionsCoveredValues}"></apex:param>
</apex:actionSupport>
</apex:selectList>
<apex:pageBlock>
<table class="list" border="0" cellpadding="0" cellspacing="0" id="dataBlock">
<tr>
<b>Scheduled Date</b>
</tr>
<tr>
<td>
</td>
<apex:repeat value="{!headDays}" var="days">
<th style="background-color:#00BFFF;">
{!days}
</th>
</apex:repeat>
</tr>
<tr class="headerRow ">
<th style="background-color:#00BFFF;">Photographer: Full Name</th>
<apex:repeat value="{!headDates}" var="heading">
<th style="background-color:#00BFFF;" class="headerRow ">
{!heading}
</th>
</apex:repeat>
</tr>
<apex:repeat value="{!DataRows}" var="dRow">
<apex:repeat value="{!dRow.contacts}" var="photo">
<tr>
<td style="background-color:#d4dadc;">
<a href="https://apartments--pre.cs20.my.salesforce.com/{!photo.Id}"> {!photo.Name} </a>
</td>
<apex:repeat value="{!dRow.cases}" var="count">
<td>
{!count.casenumber}
</td>
</apex:repeat>
</tr>
</apex:repeat>
</apex:repeat>
</table>
</apex:pageBlock>
</apex:outputPanel>
</apex:form>
</apex:page>
感謝