You need to sign in to do that
Don't have an account?
Selected Picklist value
Hello, i am struggling here with a little problem. Actually i almost do the exact same things like here:
http://wiki.developerforce.com/index.php/Extended_Functionality_of_Visualforce_-_Part_2
but it not everything works.
The problem:
I have an object with a field, Category__c, so every record has a category. I have a VF page where the categories are listed in a picklist and the records in a datatable. I want that it shows only the records with the category i have chosen.
What works:
I have rendered the picklist with this:
public List<SelectOption> getCategories()
{
List<SelectOption> options = new List<SelectOption>();
Schema.DescribeFieldResult fieldResult = obj__c.Category__c.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
options.add(new SelectOption('All', 'All'));
for( Schema.PicklistEntry f : ple)
options.add(new SelectOption(f.getLabel(), f.getValue()));
return options;
}
And the datatable works too.
Now i need the selected value in the picklist. I tried this(like in the link above):
String category;
public String getCategory() { return this.category; }
public void setCategory(String s) { this.category = s; }
But when I do System.Debug, it says category is null, but i see that 'All' is selected.
The list looks like this:
<apex:selectList value="{!category}" id="category" size="1" required="true">
<apex:selectOptions value="{!Categories}"/>
<apex:actionSupport event="onchange" rerender="dataTable"/>
</apex:selectList>
As you see i am facing 2 problems.
1. I don't get the selected Picklistvalue from the VF-Page
2. the "onchange" event doesn't work. Nothing happens when I change the Picklistvalue.
apex codde:
<apex:page controller="DynamicPickListValues21">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
<!-- <apex:actionregion > -->
<h1>Type:</h1> <apex:selectList id="countries" value="{!selectone}" size="1" required="true" >
<apex:selectOptions value="{!Opt1}"/>
<apex:actionSupport event="onchange" action="{!updateSelected}" reRender="abc"/>
</apex:selectList>
<!-- </apex:actionregion> -->
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock >
<apex:pageBlockTable value="{!Acc}" var="A" id="abc">
<apex:column value="{!A.name}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
controller code:
public class DynamicPickListValues21{
public string selectone{get;set;}
public list<Account> Acc{get;set;}
public List<SelectOption> getOpt1()
{
List<SelectOption> options = new List<SelectOption>();
Schema.DescribeFieldResult fieldResult = Account.Type.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
for( Schema.PicklistEntry f : ple)
{
options.add(new SelectOption(f.getLabel(), f.getValue()));
}
return options;
}
public void updateSelected() {
Acc = [select Name from Account where Type = :selectone];
}
}