function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mthobisi NdlovuMthobisi Ndlovu 

VF page Displaying List Value + Variables on the PageBlockTable from Controller

Hi Guys

I have requirement where I need to display a report on a VF page based on the selected fiscal year. However I am having difficulty doing so.

both my list and variable are not getting set. I don't know what could be the problem. This is my 3rd VF page so I am not that clued up them.

Also is there a way to validate if the list is null on the VF page. if it is null an error must be displayed. Thanks in advance for your assistance.

Code is below.

<apex:page controller="SkillsDevBBBEEScorecardController">
<apex:form id="form"> 
    <apex:pageBlock id="pBlock">
         <apex:outputLabel >Select Financial Year:</apex:outputLabel>
         <apex:selectList value="{!selectedValue}" multiselect="false" size="1" > 
            <apex:selectOptions value="{!FiscalYearOptions}" /> 
        </apex:selectList> 
        <apex:commandButton id="btn" value="Run Report" action="{!SelectedValue}" reRender="pBlock,ResultsPanel"/>
    </apex:pageBlock>
    <apex:pageBlock id="ResultsPanel" >
        <apex:pageBlockSection >
            <apex:facet name="header">
               <apex:outputText value="{!ReportTitle}"/>
            </apex:facet>
            <apex:pageBlockTable value="{!scorecardWeightingACIEmployees}" var="employees" columnsWidth="2%,70%,5%,5%,5%,5%,5%">          
                 <apex:column headerValue="#">
                    <apex:outputLabel value="{!employees.Description_Item_Number__c} ">
                    </apex:outputLabel> 
                 </apex:column>
                 <apex:column headerValue="Criteria">
                    <apex:outputLabel value="{!employees.Criteria__c}">
                    </apex:outputLabel>
                 </apex:column>
                 <apex:column headerValue="Weighting Points">
                    <apex:outputLabel value="{!employees.Weighting_Point__c}">
                    </apex:outputLabel>
                 </apex:column>
                 <apex:column headerValue="Compliance Target">
                    <apex:outputLabel value="{!employees.Compliance_Target__c}">
                    </apex:outputLabel>
                 </apex:column>
                  <apex:column headerValue="Percentage">
                     <apex:variable value="{!employeesAchievedPercentage}" var="emp">
                     </apex:variable>
                 </apex:column>
                 <apex:column headerValue="Points">
                    <apex:outputLabel value="0">
                    </apex:outputLabel>
                 </apex:column>
            </apex:pageBlockTable>  
        </apex:pageBlockSection>
    </apex:pageBlock>
   </apex:form>
</apex:page>
public with sharing class SkillsDevBBBEEScorecardController {
	
	private static final Integer PREVIOUS_FISCAL_YEARS = 5;
	
	public String selectedValue;
	public Decimal employeesAchievedPercentage {get; set;}
	public Decimal employeesAchievedPoints {get; set;}
	public List<B_BBEE_Scorecard_Weighting__c> scorecardWeightingACIEmployees{get; set;}
    public PageReference selectedValue() {
        return null;
    }	
    
    public SkillsDevBBBEEScorecardController() {
    	scorecardWeightingACIEmployees = new List<B_BBEE_Scorecard_Weighting__c>();
    	scorecardWeightingACIEmployees = getScorecardWeightingACIEmployees();
    }
	
	public List<SelectOption> getFiscalYearOptions() {
		List<SelectOption> options = new List<SelectOption>();
		List<String>  selectOptionValues = UtilFiscalYear.getFiscalYears(PREVIOUS_FISCAL_YEARS, null);
		String firstOption = '--None--';
		options.add(new SelectOption('',firstOption));
		for (String option: selectOptionValues) {
		  	options.add(new SelectOption(option,option));
		}
		
		 return options;
	}
	public String getReportTitle() {
		String title = null;
		if (selectedValue != null) {
			title = 'Skills Development B-BBEE Scorecard Report for '+selectedValue;
		}
		return title;
	}	
	public String getSelectedValue() {
        return selectedValue;
    }
 
   public void setSelectedValue(String selected) {
       System.Debug('Set selectedValue ------>>>>>>>>: ' + selected);
        this.selectedValue = selected;
    }
	
	public Decimal getEmployeesAchievedPercentage() {
		return employeesAchievedPercentage;
	}
	
	public void setEmployeesAchievedPercentage(String selectVal) {
		System.Debug('employeesAchievedPercentage ------>>>>>>>>: ' +selectedValue);
		this.employeesAchievedPercentage = BBBEEScorecardService.calculateTargetAchievedPercentageForACIEmployees(Integer.valueOf(selectedValue));	
	}
	
	public List<B_BBEE_Scorecard_Weighting__c> getScorecardWeightingACIEmployees() {
			 System.Debug('List Display selectedValue ------>>>>>>>>: ' +selectedValue);
			if (scorecardWeightingACIEmployees == null) {
				scorecardWeightingACIEmployees = BBBEEScorecardWeightingSelector.findWeightingForACIEmployeesByFiscalYear(Integer.valueOf(selectedValue));
			}
			return scorecardWeightingACIEmployees;
	}
}

please let me know if you need any clarity.