Visualforce 'Conversion Error setting value' -- binding problem with selectCheckboxes
I am getting a 'Conversion error setting value' when I try to save a record in my controller extension. The page looks the way I would expect, but when I select one or more checkboxes, it gives my that error. I'm not seeing what the error is here. Thanks for the help.
The page:
<apex:pageBlockSectionItem >
<apex:OutputLabel value="Assigned Areas of Coverage" for="books" />
<apex:selectCheckboxes value="{!selectedBooks}"
layout="pageDirection" id="books">
<apex:selectOptions value="{!options}" />
</apex:selectCheckboxes>
</apex:pageBlockSectionItem>
The controller:
public String[] selectedBooks {get; set;}
public List<SelectOption> options
{
get
{
List<SelectOption> result = new List<SelectOption>();
List<String> optionNames = bookNames(books);
optionNames.sort();
for(String n : optionNames){
if(!blacklist.contains(n)){
result.add(new SelectOption(n, n));
}
}
return result;
}
}
private List<Book__c> books
{
get
{ if (books == null){
books = [select Id, Name from Book__c];
}
return books;
}
set;
}
private List<String> bookNames(List<Coverage__c> coverage)
{
List<String> result = new List<String>();
for(Coverage__c c : coverage){
result.add(c.Book__r.Name);
}
return result;
}
private List<String> bookNames(List<Book__c> books)
{
List<String> result = new List<String>();
for(Book__c b : books){
result.add(b.Name);
}
return result;
}
private List<Id>开发者_运维知识库; bookIDs(List<String> bookNames)
{
List<Id> result = new List<Id>();
Set<String> bookNamesSet = new Set<String>(bookNames);
for(Book__c b : books){
if(bookNamesSet.contains(b.Name)){
result.add(b.Id);
}
}
return result;
}
I think you have to post more code and it's not clear what exactly you wish to achieve:
What's your actual "command" function, I don't see any <apex:commandButton action="{!fun}" ... > and not a single function from the controller looks like "public void fun()" or "public PageReference fun()" - I especially mean the part about taking no input arguments.
Your code does not compile, I've replaced Book__c with Account and Coverage with Contact, but for example the "blacklist" variable in
if(!blacklist.contains(n)){
is undefined. I can assume that this is same as "result", but you know... garbage in, garbage out. We might need just the part you've omitted ;) Also - can you replicate the problem using standard Salesforce objects so it's easier to test for us?
"selectedBooks" is read in the page but you never set value? Not even to the simplest selectedBooks = new String[]... The uninitialized variable a is solution to similar problem discussed on Salesforce message board.
Just a random thought - for bookIDs() function you might be better using Map<Id, Book__c> or Map<Id, String>. The first one can even be instantiated directly from [SELECT Id, Name FROM Book] if you need it. You want set of IDs - use the keySet() method afterwards. You want a list of books - use the values().
精彩评论