-3

I have defined a SelectList under pageBlockButtons. The problem is top part of SelectList is getting rendered properly [selecting Temporary from list opens another Selectlist as expected], but bottom part is not working.

To replicate the issue:

Try it in your Org; you would find a SelectList next to Test1 button (both on top part and lower part -- Pls see the screen shot).

Lets test Using TOP part (Pls see the screen shot): Select Temporary from the drop down box, immediately a new DropDown shows next to it. -- This is fine.

Test Using Lower part (Pls see the screen shot): Select Temporary from the drop down box, in this time new DropDown does not show. -- This is NOT fine.

VF Page

<apex:page controller="Cntl_SelectListTest1">
    <apex:form id="frm">
        <apex:pageBlock id="pb2">
            <apex:pageBlockButtons location="both">                                
              <apex:commandButton value="Test1"/>
              <apex:selectList id="selected_list" value="{!dropdown1}" required="false" size="1">
                        <apex:selectOption itemvalue="1" itemLabel="Permanent"/>
                        <apex:selectOption itemvalue="2" itemLabel="Temporary"/>
                        <apex:actionSupport event="onchange" reRender="frm" action="{!change}"/>
              </apex:selectList>
                &nbsp;    
              <apex:selectList id="dropdown2" required="false" value="{!dropdown2}" size="1" rendered="{!IF(options != null && options.size > 0, true, false)}">                
                        <apex:selectOptions value="{!options}" />
                        <apex:actionSupport event="onchange" reRender="frm" />
              </apex:selectList>
            </apex:pageBlockButtons>                                
        </apex:pageBlock>
    </apex:form>        
</apex:page>

Controller

public class Cntl_SelectListTest1 {
    public String dropdown1{get; set;}
    public String dropdown2{get; set;}
    public List<SelectOption> options{get; set;}

    public void  change() {        
        if(dropdown1 == '1') {                    
            options = new List<SelectOption>();
        } else if(dropdown1 == '2') {                    
            options = new List<SelectOption>();
            options.add(new SelectOption('1','1 Month'));
            options.add(new SelectOption('3','3 Months'));
            options.add(new SelectOption('6','6 Months'));   
            options.add(new SelectOption('12','1 Year'));
        }
   }

}

enter image description here

Please help...

enter image description here

  • What is not working here? – Tushar Sharma Dec 1 '16 at 11:17
  • @TusharSharma: The lower selectList. If I select lower selectList, it does not work. – Kamruzzaman Dec 1 '16 at 11:51
  • When you are saying lower this means dropdown2. Also I don't find any action which you are performing. You are just printing a debug. So the method does not get called? – Tushar Sharma Dec 1 '16 at 11:53
  • No! Lower means the highlighted section + Test1 button. And top parts mean, the Test1 button + selectLists (not highlighted in the snap). – Kamruzzaman Dec 1 '16 at 11:57
  • @TusharSharma: If you copy-paste the code in your org and try out the same, you would find the top part is working absolutely fine. And, I want the lower part to work similarly.. – Kamruzzaman Dec 1 '16 at 11:58
1

I found a few posts in Salesforce developer's forum about this issue: https://developer.salesforce.com/forums/?id=906F000000098qWIAQ and https://developer.salesforce.com/forums/?id=906F000000097vZIAQ

I couldn't find any explication of why it happens at a quick look, but apparently the most common solution to achieve the desired behavior is to split the pageBlockButtons in two. Instead of:

<apex:pageBlockButtons location="both"> 
  ....
</apex>pageBlockButtons>

You would have one pageBlockButtons section with location="top" and another one with location="bottom". There are some examples in the links I posted if you need some extra help.

  • Thanks @Mauricio I followed this approach only (split the pageBlockButtons in two). I checked the links, but unfortunately it's not applicable to my case. – Kamruzzaman Dec 1 '16 at 15:46
  • @Robi - If it is not applicable in your case why did you accept the answer. – Eric Dec 2 '16 at 8:54
  • @Eric: The links are not applicable to my issue. Otherwise; the suggestion provided by Mauricio was correct. – Kamruzzaman Dec 2 '16 at 8:57
  • @Eric: But, if anyone provides more specific answer (with VF page + controller), I shall accept that... – Kamruzzaman Dec 2 '16 at 9:04

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.