You need to sign in to do that
Don't have an account?

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;
}
}
}
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.
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.