Show User List, Month List, Year List in Selected List In salesfore

Requirement: Create a Vf Page where Show Three drop down first List of user , List of Month,
List of year, and after selecting all values redirect to another page

Solution:

Class Code:

public class ListofUserController {

    public List<selectOption> lstSelectMonth{get; set;}
    public string strSelectMonth {get; set;}
    public List<selectOption> lstSelectYear{get; set;}
    public string strSelectyear{get; set;}
    public list<SelectOption> options{get;set;}
    public string UserId{get;set;}
    public boolean boolIsShowContact{get;set;}
    public boolean boolIsShowCase{get;set;}
    public boolean boolIsShowButton{get;set;}
    public boolean isShowErrorMessage{get;set;}
    public Id currentUserID;
    public string adminuserName;
    public ListofUserController()
    {
    
        List<User>  listUserDetail  = new List<User>();
        adminuserName = userinfo.getProfileID();

        currentUserID = UserInfo.getUserId();

        List<Profile> PROFILE = [SELECT Id, Name FROM Profile WHERE Id=:adminuserName LIMIT 1];

        String MyProflieName = PROFILE[0].Name;

        if(MyProflieName =='System Administrator')  
        {
            listUserDetail = [select id,Name,UserRoleId,UserRole.Name,ProfileId from User where isActive=true order by Name asc];
        }
        else
        {
            listUserDetail = [select id,Name,UserRoleId,UserRole.Name,ProfileId from User where ID=:currentUserID and isActive=true order by Name asc];
        }     
        if(listUserDetail !=null && listUserDetail.size()>0)
        {
            options = new list<SelectOption>();
            options.add(new SelectOption('','--Select--'));
            for(User uval : listUserDetail )
            {
                options.add(new SelectOption(uval.id,uval.Name));
            }
        }
        ShowMOnth();
        ShowYear();
        ShowButton();        
    }
    
    public Void ShowMOnth()
    {
        boolIsShowContact =true;
        lstSelectMonth= new list<Selectoption>();                              
        lstSelectMonth.Add(new SelectOption('','--Select--'));
        integer Month = 12;
        for(integer count = 1; count <= Month ; count++)
        {
            lstSelectMonth.Add(new SelectOption(string.valueof(count),string.valueof(count)));
           
        }  
       
    }
    
    public Void ShowYear()
    {
      
        boolIsShowCase = true;
        lstSelectYear= new list<Selectoption>();                              
        lstSelectYear.Add(new SelectOption('','--Select--'));        
        integer currentYear = System.Today().year();
        for(integer count = 2000; count <= currentYear ; count++)
        {
            lstSelectYear.Add(new SelectOption(string.valueof(count),string.valueof(count)));
        
        }       
    }
    public void ShowButton()
    {
        boolIsShowButton = true;
    }
    public PageReference ShowData()
    {
        PageReference redirectPage;
        if(strSelectMonth==''||strSelectMonth==null|| UserId ==''||UserId==null ||strSelectyear==''||strSelectyear==null)
        {
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.Error,'Please Select User, Month and Year!!' ));  
            return null;
        }
        else
        {
            redirectPage = new PageReference('/apex/anotherVFpage?uid='+UserId+'&M='+strSelectMonth+'&Y='+strSelectyear);
            redirectPage.setRedirect(true);    
            return redirectPage;
        }

    }

}


Page Code

<apex:page controller="ListofUserController">


 <apex:form >
    <apex:outputPanel id="idoutPanlMsg">
            <apex:pageMessages id="idErrorMsg"></apex:pageMessages>
        </apex:outputPanel>
    <apex:outputPanel id="idMain">
       <apex:pageBlock >
           <apex:pageBlockSection title="User List">
               <apex:selectList size="1" value="{!UserId}">
                   <apex:selectOptions value="{!options}"></apex:selectOptions>
                  <!-- <apex:actionSupport action="{!ShowMOnth}" event="onchange" reRender="cont"/>-->
               </apex:selectList>
                    
                  
           </apex:pageBlockSection>
           <apex:outputPanel id="cont">
           <apex:pageblockSection title="Month"  rendered="{!boolIsShowContact}">
                  <apex:selectList size="1" value="{!strSelectMonth}" id="test">
                      <apex:selectOptions value="{!lstSelectMonth}"></apex:selectOptions>
                   <!--<apex:actionSupport action="{!ShowYear}" event="onchange" reRender="case"/>-->
                  </apex:selectList>
           </apex:pageBlockSection>       
                 </apex:outputPanel>
                 <apex:outputPanel id="case" >
           <apex:pageBlockSection title="Year" rendered="{!boolIsShowCase}">
           <apex:selectList size="1" value="{!strSelectyear}" id="test">
                      <apex:selectOptions value="{!lstSelectYear}"></apex:selectOptions>
                     
                  </apex:selectList>
           </apex:pageblockSection>
           </apex:outputPanel>
          
          
       </apex:pageBlock>
       
            
       <apex:outputPanel id="btnOutpanelId" rendered="{!lstSelectYear != null}">
       <apex:commandButton reRender="idoutPanlMsg" style="margin-left:250px;" value="Show Expense Sheet" rendered="{!boolIsShowButton}" action="{!ShowData}" id="tt"/>
         
       </apex:outputPanel>
       
    </apex:outputPanel>  
    </apex:form>
  
</apex:page>


Snapshot:



Comments

Popular posts from this blog

Salesforce Spring 16 Release Exam (Maintenance Exam Q&A) for Developer 201 Admin

Show Hyper Link On Add Error in Salesforce Trigger

Show the Success Message before Redirecting the Detail page on Visualforce Page