[SalesForce] Passing value from selectList to controller

I am trying to pass a value from the select list in my visual force page to the controller extension, passing it to my SOQL query. The problem is that tMonth never changes so there is never a result from my SOQL, please see my code below:

Visual force page:

<apex:page standardController="Ships_Book__c" extensions="totalsClass">

    <style type="text/css">

            .TitleFormat
            {
                font-weight:bold;
                font-size:11pt;
                padding-bottom:10px;
            }

    </style>

    <apex:pageBlock >
        <apex:form id="Test" >
            <div>
            <apex:outputLabel styleClass="TitleFormat">Month</apex:outputLabel><br/>
            <apex:selectList size="1" value="{!tMonth}" multiselect="false" >
                <apex:selectOptions value="{!Months}"></apex:selectOptions>
                <apex:actionSupport event="onChange" action="{!setTotalAgent}"/>
            </apex:selectList><br/><br/><br/> 
            <apex:outputLabel value="{!test}"></apex:outputLabel><br/><br/>
            <apex:outputLabel styleClass="TitleFormat" style="margin-bottom:10px">Total Agency Fee</apex:outputLabel><br/>
            <apex:outputLabel value="£{!afTotal}"></apex:outputLabel><br/><br/><br/>  
            </div>

        </apex:form>
    </apex:pageBlock>
</apex:page>

Controller

    public class totalsClass {
    private final Ships_Book__c aTotal;
    public string afTotal {get; set;}
    public string tMonth {get; set;}
    public string test{get; set;}

    public List<SelectOption> getMonths() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('1','1'));
        options.add(new SelectOption('2','2'));
        options.add(new SelectOption('3','3'));
        options.add(new SelectOption('4','4'));
        options.add(new SelectOption('5','5'));
        options.add(new SelectOption('6','6'));
        options.add(new SelectOption('7','7'));
        options.add(new SelectOption('8','8'));
        options.add(new SelectOption('9','9'));
        options.add(new SelectOption('10','10'));
        options.add(new SelectOption('11','11'));
        options.add(new SelectOption('12','12'));
        return options;
    }

    public totalsClass(ApexPages.StandardController tController) {
        this.aTotal = (Ships_Book__c)tController.getRecord();
    }

    public void setTotalAgent() {
        List<AggregateResult> TotalAg = [SELECT SUM(AGENCY_FEE__C) total FROM SHIPS_BOOK__C WHERE CALENDAR_MONTH(ARIVAL_DATE__C) =: integer.valueOf(tMonth)];
        afTotal = string.valueof(TotalAg[0].get('total'));
    }
}

Any help would be much appreciated

Best Answer

Please Exchange Your VfPage Code. Hope it will help you!

<style type="text/css">

    .TitleFormat
    {
    font-weight:bold;
    font-size:11pt;
    padding-bottom:10px;
    }

</style>

<apex:pageBlock >
    <apex:form id="Test" >
        <div>
            <apex:outputLabel styleClass="TitleFormat">Month</apex:outputLabel><br/>
            <apex:selectList id="Positions" size="1" value="{!tMonth}" multiselect="false" >
                <apex:selectOptions value="{!Months}"></apex:selectOptions>
                <apex:actionSupport event="onchange" reRender="values" action="{!setTotalAgent}"/>
            </apex:selectList><br/><br/><br/> 
            <apex:outputLabel value="{!test}"></apex:outputLabel><br/><br/>
            <apex:outputLabel styleClass="TitleFormat" style="margin-bottom:10px">Total Agency Fee</apex:outputLabel><br/>
            <apex:outputLabel value="£{!afTotal}" id="values"></apex:outputLabel><br/><br/><br/>  
        </div>
    </apex:form>
</apex:pageBlock>