You need to sign in to do that
Don't have an account?
Capture the selected picklist value from the visualforce page and pass it to the Apex controller!!!!
I have requirement, which is as follows..
When a user selects a particular Agent Id , all the details of that particular Agent Id should get populated on the visual force page.... I am not able to capture the selected picklist value and pass it to the Apex Controller ... Please help me..
Please guide as to where am I going wrong...
Class
public class AgentandOrderController{
Agent__c Agent;
string searchText;
List<Agent__c> result;
Integer selected;
Integer AgentId;
public String getAgent() {
return null;
}
public List<Agent__c> getresult() {
return result;
}
public Integer getAgentId() {
return selected;
}
public void setAgentId(Integer val) {
selected=val;
}
public List<SelectOption> getItems() {
List<SelectOption> options = new List<SelectOption>();
options.add(new selectOption('001', '001'));
options.add(new selectOption('002', '002'));
options.add(new selectOption('003', '003'));
options.add(new selectOption('004', '004'));
return options;
}
public PageReference search() {
result=[select Agent_Address__c from Agent__c where Name=: ApexPages.currentPage().getParameters().get('options')];
System.debug('options : '+options);
return null;
}
}
Page
<apex:page controller="AgentandOrderController" >
<apex:form >
<b>Agent Information</b>
<apex:pageblock >
<apex:pageBlockSection id="section1">
<apex:pageBlockSectionItem >
<apex:panelGrid columns="2">
<apex:actionRegion >
<apex:outputLabel value="Agent Id" for="agentId"/>
<apex:selectList value="{!agentId}" multiselect="false" size="1" onchange="search()" >
<apex:selectOptions value="{!items}" />
</apex:selectList>
</apex:actionRegion>
</apex:panelGrid>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageblock>
<b>Order Information</b>
<apex:pageBlock >
<apex:pageBlockSection id="section2">
<apex:pageBlockSectionItem >
<apex:panelGrid columns="2">
</apex:panelGrid>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Thank You
Hi,
For this make use of apex:actionFunction.
Try the below code snippet as reference.
<apex:page controller="getpicklstval" >
<script>
function search()
{
// alert('hi');
sendvaltocontroller();
}
</script>
<apex:form >
<apex:selectList value="{!agentId}" multiselect="false" size="1" onchange="search()" >
<apex:selectOptions value="{!items}"/>
</apex:selectList><br/>
<apex:actionFunction name="sendvaltocontroller" action="{!check}"/>
</apex:form>
</apex:page>
===Apex Controller=====
public class getpicklstval {
public String agentId{get;set;}
public List<SelectOption> getItems() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('--None--','--None--'));
options.add(new SelectOption('US','US'));
options.add(new SelectOption('CANADA','Canada'));
options.add(new SelectOption('MEXICO','Mexico'));
return options;
}
public PageReference check()
{
system.debug('____________'+agentId);
return null;
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Hi Thanks for the response, but.. here I ma trying to pass the selected picklist value to my SOQL statement in the apex controller... but I dont think i am heading in the right way.. Can i make use of <apex:param> to capture the selsected value.. please advice..
Try this. let me know if it doesnt work.
Hi Kavya ,
I am facing the same issue . Please let me know if you have found the solution to this !
In page there is a picklist field which is having items. When we enter fields in a page we should assign field names to sObjects custom fields as follows
public class LeadController {
public SelectOption[] leadsrcs{get;set;}
public String title{get;set;}
String[] leadsrc=new String[] {'----None----', 'Web','Phone Inquiry','Partner Referral','Purchased List','Other'};
this.leadsrcs = new SelectOption[]{};
for(String ls : leadsrc){
this.leadsrcs.add(new SelectOption(ls,ls));
}
public PageReference saveandnew() {
MyLead__c ld = new MyLead__c();
ld.Title__c = title; //this working
ld.Lead_Source__c = leadsrcs; // this is not working saying like Illegal assignment from LIST<System.SelectOption> to String
Could you please let me know how to assign selectOption to String which is picklist?
https://developer.salesforce.com/forums/#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Visualforce_Development&criteria=OPENQUESTIONS&id=906F0000000AiF4IAK
For future references, one can use something like: