+ Start a Discussion
Joe HayesJoe Hayes 

ReRender Picklist via apex controller

I have a vf page with 2 picklists.
I need the second picklist to update when the first one changes. Rather than using selectOption for the second picklist I want to pass through the field name to rerender so that I can update the values without having to update the controller.
 
For this I though about using the following:
<apex:column headerValue="Picklist1">
                <apex:selectList value="{!Picklist1}" multiselect="false" size="1">
                <apex:selectOption itemValue="a" itemLabel="a"/>
                <apex:selectOption itemValue="b" itemLabel="b"/>
                <apex:selectOption itemValue="c" itemLabel="c"/>
                <apex:actionSupport event="onchange" reRender="b"/>
                </apex:selectList>
                </apex:column>

                <apex:column headerValue="Picklist2">
                <apex:inputField value="{!Picklist2}" id="b"></apex:inputField>
                </apex:column>
Public String Picklist1{get;set;}
Public String Picklist2 {get;set;}

  {
        if(Picklist1 == 'a'){
            Picklist2 = 'del.a__c';
        } else if (Picklist1 == 'b'){
            Picklist2 = 'del.b__c';
        }else if (Picklist1 == 'c'){
            Picklist2 = 'del.c__c';
        }else {
            Picklist2 = null;
        }
    }

I have 3 picklist fields (a,b & c) on the custom object (del) but I want picklist1 to select which picklist (a,b or c) depending.

Hope this makes sense.

 
Best Answer chosen by Joe Hayes
Amit Chaudhary 8Amit Chaudhary 8
Create one Apex Method and call the same method from your ActionSupport

  <apex:actionSupport event="onchange" reRender="b" action="{!ChangePicklist}"/>

Please check below post for same issue
1) http://www.infallibletechie.com/2012/10/dependent-picklist-using-apex-in.html

Let us know if this will help you
 

All Answers

Amit Chaudhary 8Amit Chaudhary 8
Create one Apex Method and call the same method from your ActionSupport

  <apex:actionSupport event="onchange" reRender="b" action="{!ChangePicklist}"/>

Please check below post for same issue
1) http://www.infallibletechie.com/2012/10/dependent-picklist-using-apex-in.html

Let us know if this will help you
 
This was selected as the best answer
Joe HayesJoe Hayes
Thanks Amit,

I had previously seen that link but cannot seem to get it to work, I receive an error "Could not resolve the entity from <apex:inputField> value binding '{!Picklist2}'.

I can't seem to work it out.
Amit Chaudhary 8Amit Chaudhary 8
Picklist2 is custome Picklist which can not be bind with <apex:inputField>. Please select <apex:SelectList