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
Bhaskar ChowdaryBhaskar Chowdary 

wrapper class not working please help

a

<apex:page controller="wrapperClassController2">   
<apex:form >       
<apex:pageBlock >           
<apex:pageBlockTable value="{!contacts}" var="c" id="table">               
<apex:column value="{!c.con.Name}" />               
<apex:column headerValue="Email">                 
<apex:outputField value="{!c.con.Email}" styleClass="c.style"/>            
</apex:column>               
<apex:column value="{!c.con.Phone}" />           
</apex:pageBlockTable>       
</apex:pageBlock>   
</apex:form>
</apex:page>

 

 

 

 

 

 

 

and the class is

 

public class wrapperClassController2 {   
//Our collection of the class/wrapper objects cContact    
public List<cContact> contactList {get; set;}       
//This method uses a simple SOQL query to return a List of Contacts  
 public List<cContact> getContacts(){       
 if(contactList == null){           
contactList = new List<cContact>();                   
for(Contact c : [select Id, Name, Email, Phone from Contact limit 10]){              
String style = getStyle(c);            
contactList.add(new cContact(c,style));          
}       
    }      
      return contactList;  
       }       
       public String getStyle(Contact con){    
       String style = 'green';    
       if(con.Email.contains('.com')){        
       style = 'red';     
       }               
       return style;   
       }      
       public class cContact{       
       public Contact con {get; set;}      
        public String style {get; set;}             
         public cContact(Contact c, String style){           
         this.con = c;          
          this.style = style;       
      }   
   }
}

 

Peter_sfdcPeter_sfdc
So you've created a wrapper class to somehow store a CSS style associated with the record?

What part doesn't work? Is it not getting assigned in the wrapper class style property? Is it not getting read? What does your page look like?

One problem I see is that you are not binding to the wrapper class style property in your page:

styleClass="{!c.style}"

The way you've written it, the VF page renderer will attempt to evaluate "c.style" as a css setting, which is not valid, and will therefore be ignored.
Puja_mfsiPuja_mfsi

HI,

You need to use "style" rather than "styleClass" attribute.

 

<apex:page controller="wrapperClassController2">
         <apex:form >
                  <apex:pageBlock >
                           <apex:pageBlockTable value="{!contacts}" var="c" id="table">
                                     <apex:column value="{!c.con.Name}" />
                                     <apex:column value="{!c.con.Email}"  style="background-color:{!c.style};"  />
                                     <apex:column value="{!c.con.Phone}" />
                           </apex:pageBlockTable>
                   </apex:pageBlock>
         </apex:form>
</apex:page>

 

Please let me know if u have any issue on same and if this post helps u please throw KUDOS by clicking on star at left.