1

Here is the Visualforce code:

<apex:panelGrid id="pgId1" columns="13" cellpadding="4" cellspacing="0" styleClass="tblFilters">
    <apex:outputLabel value="Show Plan: " />
    <apex:selectList value="{!strShowPlanType}" size="1" required="true" id="slIdPlan" style="width:87px;">
        <apex:selectOptions value="{!ShowPlan}"/>  
        <apex:actionSupport action="{!SelectCurrentMonthQuarterYearAsDefault}" status="contentLoadingStatus" event="onchange" reRender="pgId1,slIdMonth,slIdQuarter"/>  
    </apex:selectList>

    <apex:outputLabel value="Select Quarter: " rendered="{!IF(strShowPlanType == 'Quarterly',true,false)}" /> 
    <apex:selectList value="{!strQuarter}" size="1" rendered="{!IF(strShowPlanType == 'Quarterly',true,false)}" required="true" id="slIdQuarter">
        <apex:selectOptions value="{!Quarter}"/>  
    </apex:selectList>

    <apex:outputLabel value="Select Month: " rendered="{!IF(strShowPlanType == 'Monthly',true,false)}" /> 
    <apex:selectList value="{!strMonth}" size="1" required="true" id="slIdMonth" rendered="{!IF(strShowPlanType == 'Monthly',true,false)}">
        <apex:selectOptions value="{!Month}"/>  
    </apex:selectList>

    <apex:outputLabel value="Select Year: "/ > 
    <apex:selectList value="{!strYear}" size="1" required="true" id="slIdYear" style="width:81px;">
        <apex:selectOptions value="{!Year}"/>  
    </apex:selectList>

Here is the corresponding apex action function called by actionsupport:

public pageReference SelectCurrentMonthQuarterYearAsDefault()
{
    System.debug('---Called!!---');
    Date currentDate = system.today();

    strMonth = mapFullNameofMonth.get(currentDate.month());
    strYear = string.valueOf(currentDate.Year());

    integer quarterNo = integer.valueOf(math.ceil(decimal.valueOf(currentDate.month()) / 3.0));
        strQuarter = quarterNo == 1 ? 'First Quarter' : (quarterNo == 2 ? 'Second Quarter' : (quarterNo == 3 ? 'Third Quarter' : 'Fourth Quarter'));    
    system.debug('NRAC:QN:'+quarterNo);
    return null;
}

SelectMonth label& selectlist not getting rendered after selecting show plan value as 'Monthly'.

  • Added outputpanel before panelgrid...tried to rerender it on selecting plan;not working either. – Keyser.soze Nov 4 '16 at 15:05
2

It has reasons of not working.

When you use actionSupport function for first selectList it will call controller method. Now during execution, property values are assigned first, followed by method call.

Now, think of the scenario, you are selecting the first selectList and at that moment all these mandatory fields have not been entered, so actionSupport will not get executed properly.

So, either you can remove required attribute from the page or use actionFunction instead of actionSupport to pass value to controller or performing any action.

0

Removed required=true from selectlist...working now..Don't know the reason why it worked!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.