2

Controller Class --> wrapperClassController

public class wrapperClassController 

{
public wrapperClassController(ApexPages.StandardController controller){}

public List<wrapperContact> con;

public Contact cont;

public void setWrapperContact(List<wrapperContact> wc)
{ 
con= wc; }

public List<wrapperContact> getWrapperContact()
{
return con;
}

public List<wrapperContact> getContacts()
{
if(con == null)
{
con = new List<wrapperContact>();
for(Contact c : [select Id,Name,Email,Phone from Contact limit 10])
{
con.add(new wrapperContact(c));
}
}
return con;
}


public PageReference processSelected()
{
 List<Contact> selectedContacts = new List<Contact>();

 for(wrapperContact cCon: getContacts()) {
 if(cCon.selected == true) {
 selectedContacts.add(cCon.cont);
}}

System.debug('These are the selected Contacts...');
for(Contact selcon: selectedContacts) {
system.debug(selcon);
con=null;
}
return null;
}

public class wrapperContact
{
public Contact cont;
public Boolean selected;

public void setContact(Contact c)
{cont = c;}

public Contact getContact()
{return cont;}

public void setselected(Boolean s)
{ selected = s;}

public Boolean getselected()
{ return selected;}

public wrapperContact(Contact c)
{ cont = c; selected = false ; }
}
}

VF Page :-

<apex:page StandardController="Contact" extensions="wrapperClassController">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton value="Process Selected" action="{!processSelected}" rerender="table"/>
            </apex:pageBlockButtons>
            <!-- In our table we are displaying the cContact records -->
            <apex:pageBlockTable value="{!contacts}" var="c" id="table">
                <apex:column >
                    <!-- This is our selected Boolean property in our wrapper class -->
                    <apex:inputCheckbox value="{!c.selected}" />
                </apex:column>
                <!-- This is how we access the contact values within our cContact container/wrapper -->
                <apex:column value="{!c.cont.Name}" />

            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

In the above vf page, i am trying to access wrapper class object in column value but when i do i am getting Error: Unknown property 'wrapperClassController.wrapperContact.cont'
but my getter method is public only ..dunno why i am getting this unknown property error ?


Thanks in advance,
Dinesh Kumar.

0

1 Answer 1

7

In order for the VF page to access the wrapper class properties you need to define the getter and setters:

public class wrapperContact
{
public Contact cont {get;set;}
public Boolean selected {get;set;}

}

or use the defined getter methods:

c.Contact.Name
3
  • He defined the getters/setters in the wrapperContact class : public void setContact(Contact c) {cont = c;} public Contact getContact() {return cont;}
    – SF_user
    Aug 21, 2015 at 13:18
  • 1
    @SF_user - Yes, but he is using the property c.cont in the vf page and there is no getter for cont in the wrapper. he would have to use c.Contact as in my answer
    – Eric
    Aug 21, 2015 at 13:19
  • Ah yes, for the cont variable, you're right !
    – SF_user
    Aug 21, 2015 at 13:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .