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
Adam Lee 22Adam Lee 22 

Help with Re-Render on VF

Hi guys. Hope you can advice me.

On my VF section on the page layout, I have managed to get it to display the list. However, the filter (input field) does not work. e.g. When I select "Jan", I want just the records for Jan to display.

User-added image

VF
<apex:page Controller="AccountBrokerGWP" showHeader="True" sidebar="True"> 
    <apex:form >
        <apex:outputPanel id="pnlAll">
      <apex:pageBlock >
          
            <apex:pageblockSection title="Forecasts" collapsible="false" columns="1">
                 
                
                <apex:inputField value="{!forecastMonth.Broker_BPMonth__c}" >
                            <apex:actionSupport event="onchange" status="refreshstatus2" action="{!BPMonth}" reRender="pnlAll"/>
                        </apex:inputField>
                <apex:facet name="header">
                                <apex:outputText value="Forecasts"></apex:outputText>
               			 
                                </apex:facet>
               
                            </apex:pageblockSection>
 
          <apex:pageBlockTable id="table" value="{!ForecastListWrap}" var="BPWrap"  title="All Forecasts" columnsWidth="40px, 40px, 40px, 40px, 40px, 40px, 40px">
			<apex:column headervalue="GWP Forecasts" >
                    	<apex:outputLink value="{!URLFOR($Action.Business_Planning__c.View, BPWrap.BP.id)}" target="_parent">{!BPWrap.BP.Name}</apex:outputLink>
                    </apex:column>				   
                                   
              
			<apex:column value="{!BPWrap.BP.Broker_BPMonth__c}" headerValue="Month" />
            <apex:column value="{!BPWrap.BP.Broker_BP_Planned_GWP__c}" headerValue="Planned GWP" />
            <apex:column value="{!BPWrap.BP.Broker_BP_Actual_GWP__c}" headerValue="Actual GWP" />                   
              </apex:pageBlockTable>
                                      
          </apex:pageBlock>
        </apex:outputPanel>
          
    </apex:form>
    
</apex:page>
Controller
public with sharing class AccountBrokerGWP {

    public Business_Planning__c GWPForecast {get; set;}
    public ID idAcc = ApexPages.currentPage().getParameters().get('id');
    public String fMonth= ApexPages.currentPage().getParameters().get('Broker_BPMonth__c');
    public Boolean  showGWPforecast {get; set;}
    public Boolean ownForecasts {get; set;}
    public Business_Planning__c BPDetails {get; set;}
    public Business_Planning__c forecastMonth {get; set;}
    public Business_Planning__c getBP() {
        return forecastMonth;
    }
    public Boolean ExpandedView {get; set;}
    private Integer noGWPforecast {get; set;}
    public String pnlHeight {get; set;}
    private final Account acc;
    
 

    public AccountBrokerGWP(ApexPages.StandardController controller){
        this.acc = (Account) controller.getRecord();
        showGWPforecast=true;
        
    ownForecasts = True;
    String strOwnforecasts = ApexPages.currentPage().getParameters().get('OwnForecasts');
    ownForecasts = (strOwnForecasts == null) ? true : Boolean.ValueOf(strOwnForecasts);

        forecastMonth = new Business_Planning__c(Broker_BPMonth__c='');
        
    }   
    
    public void BPMonth(){  
        ownForecasts = True;
    }
    
 private final Account Account;
   
    public Account getAccount() {
        return Account;   
    }
    
     public class wrapForecast {
        public Business_Planning__c BP {get; set;}
        public Boolean selected {get; set;}
        
        public wrapForecast(Business_Planning__c r) {
            BP = r;
            selected = false;
        }

    }

    public List<wrapForecast> ForecastListWrap {get; set;}
    

   public AccountBrokerGWP(){
 
        Account = [Select Id, Name FROM Account
            WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
        
        if(ForecastListWrap == null){
            ForecastListWrap = new list <wrapForecast>();
            
            for(Business_Planning__c b: [Select Id, Broker_BPMonth__c,
            Broker_BP_Planned_GWP__c, Broker_BP_Actual_GWP__c, Name,  Broker_to_Target__c FROM Business_Planning__c
            WHERE Account__c = :idAcc])
            {
                ForecastListWrap.add(new wrapForecast(b));
            }
               
               
        }
    }

   

}


Any ideas? Ive spent hours on this and Im new to VF and APEX.

Thanks
Mudasir WaniMudasir Wani
Hey Adam,

After you change the month in the Visualforce page you need make an updated list of ForecastListWrap  which has the where clause of "fMonth" included.
Then only you will get the desired result.
 
Adam LeeAdam Lee
sorry, any ideas how and where to write it?
James LoghryJames Loghry
You're calling a method from your action called "BPMonth".  The issue here is that you're only setting a single variable in your method, one that does not effect the list you're displaying in visualforce.  In order to regenerate the list, you're going to have to requery for the Business_Planning__c records, and filter them by Broker_BPMonth__c.  In addition to doing this, you're going to have to regenerate the list of wrapper classes as well.

I suggest you move the query outside of your constructor into a separate method, so that you can re-use it for constructing the records as well as filtering the records on month selection.

Here's an example of how I would refactor your code to get the Broker_BPMonth__c selection working.. Note, it's not perfect and you may have to work through compile errors..
 
public with sharing class AccountBrokerGWP {

	public Business_Planning__c GWPForecast {get; set;}
	public ID idAcc = ApexPages.currentPage().getParameters().get('id');
	public String fMonth= ApexPages.currentPage().getParameters().get('Broker_BPMonth__c');
	public Boolean  showGWPforecast {get; set;}
	public Boolean ownForecasts {get; set;}
	public Business_Planning__c BPDetails {get; set;}
	public Business_Planning__c forecastMonth {get; set;}
	public Boolean ExpandedView {get; set;}
	public String pnlHeight {get; set;}
	public List<wrapForecast> ForecastListWrap {get; set;}
	private final Account acc;
	private final Account Account;
	private Integer noGWPforecast {get; set;}

	public Account getAccount() {
		return Account;
	}

	public Business_Planning__c getBP() {
		return forecastMonth;
	}

	public AccountBrokerGWP(){
		Account = [Select Id, Name FROM Account
			WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
		queryForecastList():
	}

	public AccountBrokerGWP(ApexPages.StandardController controller){
		this.acc = (Account) controller.getRecord();
		showGWPforecast=true;
		ownForecasts = True;
		String strOwnforecasts = ApexPages.currentPage().getParameters().get('OwnForecasts');
		ownForecasts = (strOwnForecasts == null) ? true : Boolean.ValueOf(strOwnForecasts);
		forecastMonth = new Business_Planning__c(Broker_BPMonth__c='');
	}

	public PageReference BPMonth(){
		ownForecasts = True;
		queryForecastList();
		return null;
	}

	private void queryForecastList(){
		ForecastListWrap = new list <wrapForecast>();

		for(Business_Planning__c b:
			[Select
				Id
				,Broker_BPMonth__c
				,Broker_BP_Planned_GWP__c
				,Broker_BP_Actual_GWP__c
				,Name
				,Broker_to_Target__c
			 From
			 	Business_Planning__c
			Where
				Account__c = :idAcc]){
			//You could also do this with Dynamic SOQL, but this is easier to demonstrate..
			if(forecastMonth == null || String.isEmpty(forecastMonth.Broker_BP_Month__c) || forecastMonth.Broker_BP_Month__c == b.Broker_BPMonth__c){
				ForecastListWrap.add(new wrapForecast(b));
			}
		}
	}

	public class wrapForecast {
		public Business_Planning__c BP {get; set;}
		public Boolean selected {get; set;}

		public wrapForecast(Business_Planning__c r) {
			BP = r;
			selected = false;
		}
	}
}