You need to sign in to do that
Don't have an account?
Jamsie
Pass Parameter from Page to Controller Method
Hi everyone,
I am trying to style rows in a table of Tasks based upon the due date and time of the tasks.
<apex:page showHeader="false" controller="atTaskListController"> <style type="text/css"> .normalPriority{font-weight:bold; background-color: #FFFFCC;} .highPriority{font-weight:bold; background-color: #FFFFCC;} .critical Priority{font-weight:bold; background-color: #FFFFCC;} </style> <apex:outputPanel id="taskList"> <apex:pageBlock title="Callback Task List" > <apex:pageBlockTable value="{!tasks}" var="t"> <apex:column headerValue="Task"> <apex:outputLink value="/{!t.id}" target="_parent"> {!t.Task_ID__c}</apex:outputLink></apex:column> <apex:column headerValue="Subject"><apex:outputLink value="/{!t.id}"> {!t.Subject}</apex:outputLink></apex:column> <apex:column value="{!t.ActivityDate}" styleClass="{!style}"/> <apex:column value="{!t.Due_Time__c}" /> <apex:column value="{!t.Priority}"/> <apex:column value="{!t.Status}"/> <apex:column value="{!t.whatid}"/> <apex:column value="{!t.OwnerId}"/> </apex:pageBlockTable> </apex:pageBlock> </apex:outputPanel> </apex:page>
public with sharing class atTaskListController { private List<Task> tasks = new List<Task>(); private Task thisTask {get;set;} Map<Id, String> styleMap = new Map<Id, String>(); public atTaskListController () { Schema.Describesobjectresult r = Task.sObjectType.getDescribe(); Map<String, Schema.RecordTypeInfo> rtMap = r.getRecordTypeInfosByName(); Id tRt = rtMap.get('Callback Request').getRecordTypeId(); tasks = [select id, whoid, whatid,OwnerId, Subject, Priority, Task_ID__c,Due_Time__c, Due_Date_Time__c, ActivityDate, Status from Task where OwnerId= :UserInfo.getUserId() AND RecordTypeId=:tRt AND (Status!='Cancelled' OR Status!='Completed')]; for(Task tk: tasks){ if(System.now()>=tk.ActivityDate){ styleMap.put(tk.id, 'overdue'); }else if(System.now()>=tk.Due_Date_Time__c.addHours(-2)){ styleMap.put(tk.id, 'criticalPriority'); }else if(System.now()>=tk.Due_Date_Time__c.addHours(-4)){ styleMap.put(tk.id, 'highPriority'); }else{ styleMap.put(tk.id, 'normalPriority'); } } } public List<Task> getTasks(){ return tasks; } public String getStyle() { return styleMap.get(thisTask.Id); } }
My problem is that I cannot figure out how to get a the task 't' from the page into the controller. I'd like to pass it to getStyle(Task t) but cannot work out how to do this. I cannot rely upon user interaction to do this, it must just happen.
Any help much appreciated.
Cheers,
James.
Use a wrapper for your tasks .... the best way to describe is point you to a similar post: http://boards.developerforce.com/t5/Apex-Code-Development/How-do-I-get-the-objects-that-have-been-selected-to-my-APEX/m-p/400411#M72030
If the logic for determining your normal, high, or critical status is relatively simple you could use a formula in your VF page. For example:
<apex:column value="{!t.Due_Time__c}" styleClass="{!IF( t.Due_Time__c < TODAY(), "normalPriority", "highPriority" )}" />
Otherwise, as Dirk mentioned above, a wrapper class with a variable to hold the style name would work well.
~ Clint
Dirk, Billy,
thanks for your help. As I'm pushed for time I went with the formula based solution but I'll remember the wrapper method for any more complex situations.
Cheers,
James.