You need to sign in to do that
Don't have an account?
passing value to apex
Ok I have read a lot about this, but still can't figure it out, I must be dumber than I thought.
Anyway I need to pass a value to my Controller from my page in a datatable:
<apex:column styleClass="{!ScheduleStatusClass}"> <apex:facet name="header"><b>Schedule Status</b></apex:facet> <apex:outputField value="{!aProject.Schedule_Status__c}" /> </apex:column>
You see the ScheduleStatusClass is a method that would return a style based on the content of {!aProject.Schedule_Status__c, but I can't find a way to get the {!aProject.Schedule_Status__c} back to my controller for my {!ScheduleStatusClass} method to see. I have been at it for 3 hours and this is driving me insane, please help!!! :smileysad:
Here is one, http://community.salesforce.com/sforce/board/message?board.id=Visualforce&message.id=3850&query.id=90162#M3850 , you can also do an advanced search for wrapper and that should return a lot of info. There is also this, http://wiki.developerforce.com/index.php/Wrapper_Class
If you want to maintain your method function to control the styles this is what you would need to do. I only threw this together in notepad so there may be some syntax type errors but it should give you the right idea.
public class wrapperClassController {
//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 style getStyle(Contact con){
String style = 'green';
if(con.Email.contains('.gov')){
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;
}
}
}
<apex:page controller="wrapperClassController">
<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>
All Answers
set the Schedule Status value in a page action method that is called out of your apex page. lifecycle of the page is
controller constructor
page action
controller binding
by the time you need the attribute, the method has already fired.
worth a shot, eh?
private String currentScheduleStatus { get; set; } public String getScheduleStatusClass() { if (currentScheduleStatus == 'In-Progress - On Schedule' || currentScheduleStatus == 'In-Progress - Ahead of Schedule') { return 'highlightGreen'; } else { return 'highlightRed'; } }
If all you want to do is change the color of text based on the value you can do something like this:
<apex:outputField value="{!aProject.Schedule_Status__c}" styleClass="{!if(OR(aProject.Schedule_Status__c='In-Progress - On Schedule','In-Progress - Ahead of Schedule'),'highlighGreen', 'highlightRed')}"/>
Yes I understand using if in the style, but I use this method because the real thing is quite more complex than the snippet of code shown in my post. This is why I am using a method.
Thanks
Here is one, http://community.salesforce.com/sforce/board/message?board.id=Visualforce&message.id=3850&query.id=90162#M3850 , you can also do an advanced search for wrapper and that should return a lot of info. There is also this, http://wiki.developerforce.com/index.php/Wrapper_Class
If you want to maintain your method function to control the styles this is what you would need to do. I only threw this together in notepad so there may be some syntax type errors but it should give you the right idea.
public class wrapperClassController {
//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 style getStyle(Contact con){
String style = 'green';
if(con.Email.contains('.gov')){
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;
}
}
}
<apex:page controller="wrapperClassController">
<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>