You need to sign in to do that
Don't have an account?
veeru_pari
Displaying picklist values with ques and answers in VF page
Hi,
I have other query where i have a custom object in that i have fields questions(data type text area),answers(answer also same ) an pick list having internal user,external user and All users. now my requirement is i want to display the pick list values in vf page and if the user selects internal option in picklist then page shpuld display question and answer related to internal and if he selects all it should display all the ques and answers.
Will you u please tell me how to achieve this req
Thanks in advance
Veeraiah
I have other query where i have a custom object in that i have fields questions(data type text area),answers(answer also same ) an pick list having internal user,external user and All users. now my requirement is i want to display the pick list values in vf page and if the user selects internal option in picklist then page shpuld display question and answer related to internal and if he selects all it should display all the ques and answers.
Will you u please tell me how to achieve this req
Thanks in advance
Veeraiah
You can do it using SelectList. Whenever the User will click on Search Buttion, You will Query on object Where the the use will be of type the selected picklist field. Here you will get List<Custom_Object> records which will have questions & answers of the slected picklist type. Just show this list on VF page.
1) public List<String> selectedValue {get;set;}
public List<SelectOption> getUserType()
{
List<SelectOption> options = new List<SelectOption>();
Schema.DescribeFieldResult fieldResult =CustomObject__c.getUserType__c.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
for( Schema.PicklistEntry f : ple)
{
options.add(new SelectOption(f.getLabel(), f.getValue()));
}
return options;
}
With our controller logic all complete, we can call the getUserType() method from our Visualforce page, and populate the <apex:selectList> tag:
2) <apex:selectList id="countries" value="{selectedValue}"
size="1" required="true">
<apex:selectOptions value="{!countries}"/>
</apex:selectList>
3) You will query in that Custom object when the Search button will be click with selectedValue which will return of list of records. Now rerender the form or Outputpanel.
Let me know if you didn't understand the scenario or any query. Happy Coding!!!
I am just giving you the template. Change your code with template
Controller :
public class VEERU_PageController{
public String selectedValue {get;set;}
public List<SelectOption> getUserType()
{
List<SelectOption> options = new List<SelectOption>();
Schema.DescribeFieldResult fieldResult = Book__c.UserType__c.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues(); // Here you will get the picklist values
options.add(new SelectOption('All','All'));
for( Schema.PicklistEntry f : ple)
{
options.add(new SelectOption(f.getLabel(), f.getValue()));
}
return options;
}
public List<Book__c> search(){
System.debug('====selectedValue===='+selectedValue); // You will get the Selected Value here
List<Book__c> temp = new List<Book__c>();
String queryString;
if(selectedValue == 'ALL') queryString ='SELECT id,Question__c,Answer__c from CustomObject__c';
else if(selectedValue == 'Internal') queryString ='SELECT id,Question__c,Answer__c from CustomObject__c WHERE UserType__c = 'Internal'';
else if(selectedValue == 'External') queryString ='SELECT id,Question__c,Answer__c from CustomObject__c WHERE UserType__c = 'External'';
temp = Database.query(queryString);
return temp;
}
}
Page
<apex:page controller="VEERU_PageController">
<apex:form id="form1">
<apex:selectList id="countries" value="{!selectedValue}"
size="1" required="true">
<apex:selectOptions value="{!UserType}"/>
</apex:selectList>
<apex:commandButton value="Search" action="{!search}" rerender="form1"/>
<!-- Take table here & display your record
-->
</apex:form>
</apex:page>
Hope this will help, If you still facing any issues, let me know! Happy Coding!!
It seems all correct to me, I am also not facing the compatibility error. May be you know this that the error is occuring due to the LHS & RHS of Assignment operator is different. Check your code or Share your code. Reply in your open ticket!
Happy Coding!!
public class FAQCu {
public List selectedValue {get; set;}
public List getUserType() {
List options = new List();
Schema.DescribeFieldResult fieldResult = FAQ__c.Users__c.getDescribe();
List ple = fieldResult.getPicklistValues();
options.add(new SelectOption('AllUsers', 'AllUsers'));
for (Schema.PicklistEntry f: ple) {
options.add(new SelectOption(f.getLabel(), f.getValue()));
}
return options;
}
public List<FAQCu__c> getSearch()
{
//System.debug('====selectedValue===='+selectedValue); // You will get the Selected Value here
List<FAQCu__c> temp = new List<FAQCu__c>(); //make list of your custom object
String queryString;
if(selectedValue=='AllUsers') queryString='SELECT Question__c,Answer__c from FAQ__c WHERE Users__c ='AllUsers'';
else if(selectedValue=='InternalUsers') queryString='SELECT id,Question__c,Answer__c from FAQ__c WHERE Users__c ='InternalUsers'';
else if(selectedValue=='ExternalUsers') queryString='SELECT id,Question__c,Answer__c from FAQ__c WHERE Users__c ='ExternalUsers'';
temp = Database.query(queryString);
return temp;
}
}