You need to sign in to do that
Don't have an account?
Issue with transfering PickList selection to Select statment
Hello everyone,
I am trying here to use the result of a Picklist value to get a list of related object. Although the Selected value is visible cleary in ViewState, it is not actuated in the related object Select statment. Why?
Thanks in advance for your help
Jerome
Controller
public with sharing class CNModConMoyCont {
public String MarqueSelected { public get; public set; }
public list<Organism__c> marqueList=[select Id, Name from Organism__c];
public list<Organism__c> getMarqueList(){return marqueList;}
public void setMarqueList(list<Organism__c> data) { marqueList=data; }
public List<SelectOption> marqueSelOpt;
public List<SelectOption> getMarqueSelOpt() {
List<SelectOption> options = new List<SelectOption>();
for (Organism__c Org : marqueList) {
options.add(new SelectOption( Org.Id, Org.Name));
}
return options;
}
public void setMarqueSelOpt(List<SelectOption> data) {marqueSelOpt=data;}
public list<Model__c> modelList { public get; public set; }
public CNModConMoyCont() {
modelList = [select Id, Name, Lien_Marque__c from Model__c where Lien_Marque__c =: MarqueSelected]; //always null
}
}
Page
<apex:page controller="CNModConMoyCont" showHeader="false" sidebar="false" id="CNModConMoy" >
<apex:form >
<apex:pageBlock >
<apex:selectList value="{!MarqueSelected}" multiselect="false" >
<apex:selectOptions value="{!marqueSelOpt}" />
</apex:selectList>
<apex:commandLink value="pick" rerender="datalist, modellist" />
<apex:outputPanel id="datalist" ><br/>
{!MarqueSelected}
</apex:outputPanel>
<apex:dataTable value="{!ModelList}" var="mod" id="modellist">
<apex:column >
<apex:outputText value="{!mod.Name}" />
</apex:column>
</apex:dataTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Since the SELECT statement is within the constructor, it will be called only when the page initializes. So, during page initialization the select value will be null.
Just add another action method with this query & call it using the commandLink action, then it will work as you expect.
Sample code:
Page:
Controller:
All Answers
Since the SELECT statement is within the constructor, it will be called only when the page initializes. So, during page initialization the select value will be null.
Just add another action method with this query & call it using the commandLink action, then it will work as you expect.
Sample code:
Page:
Controller:
Thank you very much. This was it.Simple to you but not obvious to me. I am all set now.
Thanks again for your help.
Jerome