0

VF Page:

<apex:page controller="GanttChartStreams" tabStyle="Release__c">
    <apex:include pageName="VFP_MilestoneGanttChart"/>
        <apex:form id="form">

               <apex:selectList size="1" value="{!selectedname}" multiselect="false">
                    <apex:actionSupport event="onchange" reRender="TableStream"  oncomplete="initialize();" />
                    <apex:selectOptions value="{!selectedaccnamefields}"/>  
                </apex:selectList>

                    <apex:pageBlock >             
                        <apex:pageBlockTable value="{! Streams}" var="st" columns="2" id="TableStream">
                            <apex:column value="{!st.Name}"/>
                            <apex:column value="{!st.Id}"/>                  
                        </apex:pageBlockTable>                    
                    </apex:pageBlock>   

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

Class:

public with sharing class GanttChartStreams {

     public string selectedname{

        get{
            if(selectedname == null)
                selectedname ='Model API';     
            return selectedname;
        }
        set;}

        Public List<Selectoption> getselectedaccnamefields(){
            List<Selectoption> lstnamesel = new List<selectoption>();
            lstnamesel.add(new selectOption('', '- None -'));
            for(Release__c acc :[SELECT Name,ID FROM Release__c Where Name!=Null]){
            lstnamesel.add(new selectoption(acc.id,acc.Name));
            }
            return lstnamesel; 
        }

   public PageReference calculate()
   {
       System.debug('EXECUTED');
       return null;
   }

    public  List<Release__c>  getStreams(){

        List<Release__c> li = [Select Name,ID From Release__c Where Name =: selectedname ];
        return li;

    }
}
0

1 Answer 1

2

Give this a try

<apex:page controller="GanttChartStreams" tabStyle="Release__c">
        <apex:include pageName="VFP_MilestoneGanttChart"/>
            <apex:form id="form">

               <apex:selectList size="1" value="{!selectedname}" multiselect="false" onChange="updateStreams(this.value);> 
                    <apex:selectOptions value="{!selectedaccnamefields}"/>  
                </apex:selectList>

                    <apex:pageBlock id="TableStreamPanel">             
                        <apex:pageBlockTable value="{! Streams}" var="st" columns="2" id="TableStream">
                            <apex:column value="{!st.Name}"/>
                            <apex:column value="{!st.Id}"/>                  
                        </apex:pageBlockTable>                    
                    </apex:pageBlock>   

         <apex:actionFunction name="updateStreams" action="{!getStreams}" rerender="TableStreamPanel" immediate="true">
              <apex:param name="selectedItem" assignTo="{!selectedname}" value="" />
         </apex:actionFunction>
    </apex:form>    
</apex:page>

And in your controller

public with sharing class GanttChartStreams {
     public List<Release__c> Streams   {get;set;}
     public string selectedname{

        get{
            if(selectedname == null)
                selectedname ='Model API';     
            return selectedname;
        }
        set;}

        Public List<Selectoption> getselectedaccnamefields(){
            List<Selectoption> lstnamesel = new List<selectoption>();
            lstnamesel.add(new selectOption('', '- None -'));
            for(Release__c acc :[SELECT Name,ID FROM Release__c Where Name!=Null]){
            lstnamesel.add(new selectoption(acc.id,acc.Name));
            }
            return lstnamesel; 
        }

   public PageReference calculate()
   {
       System.debug('EXECUTED');
       return null;
   }

    public  void  getStreams(){

        system.debug('SelectedName is: ' + seletedname);
        Streams = [Select Name,ID From Release__c Where Name =: selectedname ];

    }
}

Adding the apex function will work similar to the support function but instead we call it on the onchange event in the select, and pass in the value that is selected. Then when we set the apex param to the selectedname from the controller, it should be updated without having to pass it directly into the method.

3
  • Hey JRiffe, that totally worked for me. Thanks a lot:) Commented Jul 27, 2017 at 7:45
  • Can you just please help me with one more thing. Do you know how I can pass a value like the selectedname to the other visualforce page which I already have to produce chart(chart is embedded in VFP) of it as I select a name from the selectlist Commented Jul 27, 2017 at 7:54
  • @prakhar1895 You can pass it as a query string parameter, and then in the other vfp controller, pull it out of the query string and use it there. So use String yourVar = ApexPages.currentPage().getParameters().get('varName'); And to pass it in, you just append it to your redirect.
    – JRiffe
    Commented Jul 27, 2017 at 14:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .