[Solved] on button click page load picklist value becomes null

user2542953 Asks: on button click page load picklist value becomes null
I have this below method. On the button click i am calling this method and on clicking the page gets loaded again due to which the value selected in picklist gets lost. How can i retain the value een after the page load.

Code:
public class SMI_ManageInvestmentExtension {

    private Investment__c investment;
    public Smart_Account__c smartaccount{get;set;}
    public List<Investment__c> listInvestment{get;set;}
    public List<Smart_Account__c> smartaccountlist;
    Public String smartaccountId= System.currentPagereference().getParameters().get('Name');
    public Integer size{get;set;} 
    public Integer noOfRecords{get; set;} 
    public String smartAccountName {get;set;}
    public String smartAccountowner{get;set;}
    public Boolean activeInvestments{get;set;}
    public double cashValue{get;set;}
    public double cashReservePercentage {get;set;}
    public double investmentValue {get;set;}
    public boolean autoInvest{get;set;}
    public double totalAccountValue{get;set;}
    public string selectedVal{get;set;}
    public List<Investment__c> I;
    public list<investment__c> inv;
    public Integer z;


    public SMI_ManageInvestmentExtension(){
        String st = ApexPages.currentPage().getParameters().get('oldval');
        if(st!=null && st!='')
        selectedVal=st;

       size=10; 
       }

    public ApexPages.StandardSetController setInvestmentList {


        get {
            if(setInvestmentList == null) {


                setInvestmentList = new ApexPages.StandardSetController(Database.getQueryLocator(
                      [select id,Name,Active__c,Auto_Invest_Percent__c,Symbol__c,Smart_Category__c,Shares__c,Price__c,Value__c from Investment__c where Investment__C.Smart_Account__r.Name=:smartaccountId order by Auto_Invest_Percent__c desc,Symbol__c asc]));
                setInvestmentList.setPageSize(size);  
              //  listInvestment=setInvestmentList;
                noOfRecords = setInvestmentList.getResultSize();


             }

            return setInvestmentList;
        }
        set;
    }

    public SMI_ManageInvestmentExtension(ApexPages.StandardController controller) {


       System.debug('Smart Account Id---------------------------'+smartaccountId);
       smartaccount= [select id,Name,Active_Investments__c,Auto_Invest__c,Cash_Reserve_Percent__c,Cash_Value__c,Owner.Name from Smart_Account__c where Name=:smartaccountId];

       size=10;

    }

    //Changes the size of pagination
    public PageReference refreshPageSize() {
         setInvestmentList.setPageSize(size);
         return null;
    }

    // Initialize setInvestmentList and return a list of record    

    public List<Investment__C> getAllInvestmentList() {
         listInvestment = (List<Investment__C>) setInvestmentList.getRecords();

        // investment = (Investment__C)setInvestmentList.getRecords();
         return listInvestment;
    }


    public List<SelectOption> getSmartCategory()
    {
        List<SelectOption> options = new List<SelectOption>();

        Schema.DescribeFieldResult fieldResult =
            Smart_Fund__c.Smart_Category__c.getDescribe();
        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
        options.add(new SelectOption(' ', '-None-'));
        for( Schema.PicklistEntry f : ple)
        {
            options.add(new SelectOption(f.getLabel(), f.getValue()));
        }       
        return options;
    }

    public PageReference Adjusments(){


        String strURL = ApexPages.currentPage().getUrl();
        if(strURL.containsignorecase('&oldval='))
        {
        String stRemove = strURL.SubStringafterLast('=');
        strURL = strURL.remove(stRemove);
        strURL = strURL.remove('&oldval=');

        }

        strURL = strURL+'&oldval='+selectedVal;

        system.debug('@@@@@@'+selectedVal);
        if(selectedVal ==' '){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Warning,'No Smart Category is selected'));
        }
        else{

     I = [select id,Name,Active__c,Auto_Invest_Percent__c,Symbol__c,Smart_Category__c,Shares__c,Price__c,Value__c from Investment__c where Investment__C.Smart_Account__r.Name=:smartaccountId ];

            Integer count = 0;

            for(Investment__c i: I){
                if(i.Smart_Category__c == selectedVal){
                    count++;
                }

            }

            if(count!=0){
            z = (100)/count;
            }

            for(Investment__c i: I){
                if(i.Smart_Category__c == selectedVal){
                    i.Auto_Invest_Percent__c = z;
                    i.Active__c =true;
                }
                else{
                    i.Auto_Invest_Percent__c = 0; 
                    i.Active__c =false;

                }

            } 
            try{
            update i;

            //PageReference pageRef = new PageReference(ApexPages.currentPage().getUrl());
            PageReference pageRef = new PageReference(strURL);
            pageRef.setRedirect(true);
            return pageRef;}
            catch(Exception e){

            System.debug('Exception occurred '+String.valueOf(e));
            }
    }
    return null;

    }


    public PageReference saveInvestment(){

    try{


    update listInvestment;

    }
    catch(Exception e){
    System.debug('Exception occurred '+String.valueOf(e));

    }

    return null;
    }



}

Vf Page –

Code:
   <apex:pageblockSection >
   <apex:outputlabel value="Smart Category :" style="position:absolute;left:400px;"> 
   <apex:selectList value="{!selectedVal}" multiselect="false" size="1">
        <apex:selectOptions value="{!SmartCategory}"/>
    </apex:selectList>
    <!--apex:inputField id="smartCategory" value="{!Investment__c.Smart_Fund__r.Smart_Category__c}"/-->
     <apex:commandButton value="Adjust Investment" action="{!Adjusments}" style="position:fixed;left:800px;top:272px;" />

       </apex:outputlabel>
   </apex:pageblockSection>

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.