function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
foodrunnerfoodrunner 

Controller is not being accepted

I m trying to create a vf page where the  user will search for records and add them to the opportunity. This functionality is similar to tstandard automation of adding products to the opportunity. When I attempt to add the cutom controller I recieve the following error: "Unknown Property" "String.Selected."

 

Here is my Visualforce  page

<apex:page controller="customerwrapperClassController" > 
<!-- Javascript function to check all rows in the table --> 
<script> 
function checkAll(cb) 
{ 
var inputElem = document.getElementsByTagName("input"); 
for(var i=0;i<inputElem.length;i++) 
{ 
if(inputElem[i].id.indexOf("selectLine1")!=-1) 
inputElem[i].checked = cb.checked; 
} 
} 
</script> 
<!-- End of Javascript function --> 
<apex:form > 
<apex:sectionHeader title="Step 1" subtitle="Select Contacts to send Email"/> 
<apex:pageblock > 
<apex:pageBlockSection title="Search Contacts" columns="1"></apex:pageBlockSection> 

<!-- Div to give a colored box effect --> 

<div style="border-width:2px;border-style:solid;border-color:orange;"> 

<!-- Panel grid to display boxes o accept user input values --> 
<apex:panelGrid columns="2"> 
<apex:outputLabel style="font-weight:bold;" value="Contact E-mail" ></apex:outputLabel> 
<apex:inputText value="{!userinput}"/> 
<apex:outputLabel style="font-weight:bold;" value="Contact Name" ></apex:outputLabel> 
<apex:inputText value="{!userinp}"/> 
</apex:panelGrid> 
<!-- End of panelgrid --> 
<!-- Div to position the commandbutton appropriately --> 
<div style="position:relative;left:75px;"> 
<apex:commandButton value="Search" action="{!contactsearch}" /> 
</div> 
<!-- End of div --> 
<br/> 
</div> 

<!-- End of colored box div --> 
<br/> 
<!-- Display error message --> 
<apex:pagemessage strength="2" title="Error!!" severity="error" detail="Please select a contact or enter email address to proceed" rendered="{!errormsg}"/> 
<!-- End of error message --> 

<!-- Display search results --> 
<apex:pageblocksection columns="1" title="Search results" rendered="{!NOT(ISNULL(results))}" > 
<apex:outputpanel id="Contactlist"> 

<apex:pageBlockTable value="{!results}" var="contacts"> 
<apex:column > 
<apex:facet name="header"> 
<apex:inputCheckbox onclick="checkAll(this)"/> 
</apex:facet> 
<apex:inputCheckbox value="{!contacts.selected}" id="selectLine1"/> 
</apex:column> 
<apex:column headervalue="Contact Name"> 
<apex:outputtext value="{!contacts.con.Name}"/> 
</apex:column> 
<apex:column headervalue="Account Name"> 
<apex:outputtext value="{!contacts.con.Account.Name}"/> 
</apex:column> 
<apex:column headervalue="Title"> 
<apex:outputtext value="{!contacts.con.Title}"/> 
</apex:column> 
</apex:pageBlockTable> <br/><br/> 

</apex:outputpanel> 
</apex:pageblocksection> 
<!-- End of search results --> 

<!-- Commandbutton to proceed to next screen --> 
<div style="position:relative;left:75px;"> 
<apex:commandButton value="Next" action="{!processSelected}"/> 
<apex:commandbutton value="Cancel" action="{!Cancel}"/> 
</div> 
<!-- End of Commandbutton --> 
</apex:pageblock> 
</apex:form> 
</apex:page> 

 

Here is my controller:

public class customerwrapperClassController {
    public String results { get; set; }

    public String errormsg { get; set; }

    public PageReference contactsearch() {
        return null;
    }


    public String userinp { get; set; }

    public String userinput { get; set; }

    public customerwrapperClassController() {

    }


    public customerwrapperClassController(ApexPages.StandardController controller) {

    }



    //Our collection of the class/wrapper objects Customer_Product_List_Item__c 
    public List<Customer_Product__c> productList {get; set;}
    
    //This method uses a simple SOQL query to return a List of Contacts
    public List<Customer_Product__c> getproduct(){
        if(productList== null){
            productList= new List<Customer_Product__c>();
        
            for(Customer_Product__c c : [select Id, Name from Customer_Product__c]){
                /* As each contact is processed we create a new Customer_Product_List_Item__c object and
                add it to the productList*/
                productList.add(c);
            }
        }
        return productList;
    }
    public PageReference processSelected(){
        /*We create a new list of Contacts that we be populated only with Contacts
        if they are selected*/
        List<Customer_Product__c> selectedProducts = new List<Customer_Product__c>();
        
        /*We will cycle through our list of cContacts and will check to see if the 
        selected property is set to true, if it is we add the Contact to the 
        selectedContacts list. */
        for(Customer_Product__c cCon: getproduct()){
            if(cCon.selected__c == true){
            //    selectedCustomer_Product__c.add(cCon.id);
            }
            }
         
        /* Now we have our list of selected contacts and can perform any type of 
        logic we want, sending emails, updating a field on the Contact, etc */
        System.debug('These are the selected Contacts...');
        for(Customer_Product__c con: selectedProducts){
            system.debug(con);
        }
        return null;
    }
 
    /* This is our wrapper/container class. A container class is a class, a data 
    structure, or an abstract data type whose instances are collections of other 
    objects. In this example a wrapper class contains both the standard salesforce 
    object Contact and a Boolean value */
    public class cCustomer {
        public Customer_Product__c con {get; set;}
        public Boolean selected {get; set;}
        
        /*This is the contructor method. When we create a new cContact object we pass a 
        Contact that is set to the con property. We also set the selected value to false*/
        public cCustomer(Customer_Product__c c){
            con = c;;
        }

 

Note: comments have not been updated to the custom object specifics, but is patterned after the wrapper class example. http://wiki.developerforce.com/index.php/Wrapper_Class

 

How do I solve this error? Thanks

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

You have a property in your controller called results, declared as shown below:

 

 

public String results { get; set; }

 

 

This property is a string primitive.  You are using it in the page to back a table:

 

 

<apex:pageBlockTable value="{!results}" var="contacts"> 

I am not sure if  this is acceptable to VisualForce - I'm guessing it is as you aren't seeing an error for that part of the page.  All I can surmise is that you will have a table that will have a single row backed by the string primitive.

 

However, inside the table you have:

 

 

<apex:column > 
<apex:facet name="header"> 
<apex:inputCheckbox onclick="checkAll(this)"/> 
</apex:facet> 
<apex:inputCheckbox value="{!contacts.selected}" id="selectLine1"/> 
</apex:column> 

 

 

The line highlighted in red is invalid - there is no selected property on a string primitive, so you receive the error message.  

 

Looking at your code, the wrapper class is cCustomer, but I can't see that you are using that anywhere in your controller.  I suspect you should be returning a list of cCustomers as your results rather than a single instance of a string.

 

 

 

 

 

 

 

 

 

<apex:pageBlockTable value="{!results}" var="contacts"> 
<apex:column > 
<apex:facet name="header"> 
<apex:inputCheckbox onclick="checkAll(this)"/> 
</apex:facet> 
<apex:inputCheckbox value="{!contacts.selected}" id="selectLine1"/> 
</apex:column> 

All Answers

bob_buzzardbob_buzzard

You have a property in your controller called results, declared as shown below:

 

 

public String results { get; set; }

 

 

This property is a string primitive.  You are using it in the page to back a table:

 

 

<apex:pageBlockTable value="{!results}" var="contacts"> 

I am not sure if  this is acceptable to VisualForce - I'm guessing it is as you aren't seeing an error for that part of the page.  All I can surmise is that you will have a table that will have a single row backed by the string primitive.

 

However, inside the table you have:

 

 

<apex:column > 
<apex:facet name="header"> 
<apex:inputCheckbox onclick="checkAll(this)"/> 
</apex:facet> 
<apex:inputCheckbox value="{!contacts.selected}" id="selectLine1"/> 
</apex:column> 

 

 

The line highlighted in red is invalid - there is no selected property on a string primitive, so you receive the error message.  

 

Looking at your code, the wrapper class is cCustomer, but I can't see that you are using that anywhere in your controller.  I suspect you should be returning a list of cCustomers as your results rather than a single instance of a string.

 

 

 

 

 

 

 

 

 

<apex:pageBlockTable value="{!results}" var="contacts"> 
<apex:column > 
<apex:facet name="header"> 
<apex:inputCheckbox onclick="checkAll(this)"/> 
</apex:facet> 
<apex:inputCheckbox value="{!contacts.selected}" id="selectLine1"/> 
</apex:column> 
This was selected as the best answer
foodrunnerfoodrunner

Thank you for the advice , I replaced

<apex:inputCheckbox value="{!contacts.selected}" id="selectLine1"/>

with

<apex:inputCheckbox value="{!cCustomer.Selected__c}" id="selectLine1"/>

 

works like a charm.