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
Michael SyproMichael Sypro 

Pass a variable to a controller that is not a querystring

I'm creating a visualforce page that lists every member of our sales team and all of their open tasks.  Each user's data should be separated by their own pageBlock.  

 

However, the system I have requires me to create a new method for every user.  Code below:

 

<apex:pageBlock title="Michael Holley">

<apex:dataTable value="{!MichaelHolley}" var="t" width="965" cellpadding="2">

<apex:column headerValue="Subject">{!t.Subject}</apex:column>

</apex:dataTable>

</apex:pageBlock>

 

<apex:pageBlock title="Elizabeth Drimm">

<apex:dataTable value="{!ElizabethDrimm}" var="t" width="965" cellpadding="2">

<apex:column headerValue="Subject">{!t.Subject}</apex:column>

</apex:dataTable>

</apex:pageBlock>

 

public List<Task> getMichaelHolley() {

return [select subject from task where owner.firstname='Michael' and owner.lastname='Holley' and status<>'Complete'];

}

public List<Task> getElizabethDrimm() {

return [select subject from task where owner.firstname='Elizabeth' and owner.lastname='Drimm' and status<>'Complete'];

}

 

 

Is there any way I can specify a generic getTasks() method and pass a different variable to it based on the dataTable's ID or something similiar?  That way I only need one method?  I don't think url parameters or inputText fields will work although I could be wrong...

 

Any help at all is appreciated

 

Thanks 

 

 

 

Message Edited by Michael Sypro on 06-16-2009 01:20 PM
Message Edited by Michael Sypro on 06-16-2009 01:21 PM
DrawloopSupportDrawloopSupport

Can you use a repeat tag around the pageBlock? I haven't tested the code below and I'm not sure if you'd need any wrappers or whatnot, but I hope you get the idea.

 

 

<apex:repeat value="{!salesTeamMembers}" var="s"> <apex:pageBlock value="{!s.tasks}" var="t"> <apex:column headerValue="subject"> {!t.subject} </apex:column> </apex:pageBlock> </apex:repeat>

 

 

Michael SyproMichael Sypro
What would the getTasks() method look like in that example?
Ron HessRon Hess

To make this work cleanly, you would build a data structure that had the owner name and the list of tasks for that owner.

 

i think of this as a group by class.  then you build a list of these classes.

 

then in your page you run a repeat across  this list, and inside that repeat, you have another repeat for each task.

 

 

pseduo code:

 

class  team_member { user u; List<Task> tlist; }

 

List<team_member> allTasks { get; set ;} 

 

 

then you run the queries and build a list of allTasks containing one record of team_member for each user, with their tasks added 

to the tlist.

 

 

 

in your page you have 

 

repeat value ="{!allTasks}" var=mytask

 

  pageblock {!mytask.u.lastname}

      

       datatable value={!mytask.tlist} 

 

 /pageblock

 

 

Michael SyproMichael Sypro

Thanks!  I think I'm making some progress.  Is there any way you can post some more specifics from the controller code?  I've been reading through some other posts on similiar topics and they're a bit too complex for me at the moment (just started with VF).

 

Any help at all is appreciated.

sgottreusgottreu

Maybe this will help.  I needed to list out all OpportunityLineItems by Product Family.  So I just created a list of Opportunity objects.  You could create a list of Users joined with Tasks.  You'll see from the example that one the first repeat I can pull all Opportunity fields and in your case would be the User's name and other info.  Then on the second repeat, I pull the line items and you could pull the Tasks for the user you selected.

 

Apex Class



public class picklist_values {

Schema.DescribeFieldResult F = Product2.Family.getDescribe();
List P = F.getPicklistValues();

public Opportunity Probe { get; set; }

public List ProbeProducts = new List();

Integer Counter = 1;


public picklist_values(ApexPages.StandardController stdController) {
ID id = ApexPages.CurrentPage().getParameters().get('id');
//ID id = '0068000000NyTHe';

for (Schema.PicklistEntry fam:P){
Integer i = 0;
String FamilyLabel = fam.GetLabel();

Probe = [SELECT o.Id, o.Name, o.Amount, o.ProductFamily__c, (SELECT op.Quantity, op.UnitPrice, op.TotalPrice,
op.PricebookEntry.Name, op.OpportunityId, op.PricebookEntry.ProductCode,
op.PricebookEntry.Product2.Family, op.LineCount__c
FROM OpportunityLineItems op WHERE op.PricebookEntry.Product2.Family = :FamilyLabel)
FROM Opportunity o where Id = :id];

Probe.Amount = 0;
Probe.ProductFamily__c = FamilyLabel;

for(i=0;i
Probe.Amount += Probe.opportunityLineItems[i].TotalPrice;
Probe.opportunityLineItems[i].LineCount__c = Counter;
Counter++;
}

ProbeProducts.add(Probe);
}
}

public List getProbeProducts() {
return ProbeProducts;
}

}

VisualForce Page
    <apex:repeat value="{!ProbeProducts}" var="p">
<p>{!p.ProductFamily__c}</p>
<table border='1'>
<apex:repeat value="{!p.OpportunityLineItems}" var="line">

<tr>
<td>{!line.LineCount__c}</td>
<td ><apex:outputText value="{!line.Quantity}"/></td>
<td ><apex:outputText value="{!line.PricebookEntry.ProductCode}"/></td>
<td ><apex:outputText value="{!line.PricebookEntry.Name}"/></td>
<td align="right"><apex:outputField value="{!line.UnitPrice}"/></td>
<td align="right"><apex:outputField value="{!line.TotalPrice}"/></td>
</tr>

</apex:repeat>
</table>
<p><apex:outputField value="{!p.Amount}"/></p>


</apex:repeat>

Michael SyproMichael Sypro

Ok, here's what I have so far.

<apex:repeat value="{!UserTask}" var="r" id="theRepeat"> <apex:pageBlock title="{!r.owner.FirstName & ' ' & r.owner.LastName}"> <apex:dataTable value="{!r.TaskList}" var="t" width="965" cellpadding="2"> <apex:column headerValue="Subject">t.Subject}<apex:column> </apex:dataTable> </apex:pageBlock> </apex:repeat>

 

public class ownerTask { public List<User> userTask = [select id, firstname, lastname, title from user where isactive=True and display_tasks__c=True order by lastname]; public List<User> getUserTask() { return userTask; } public class getTaskList { public List<Task> getTaskList() { return [select subject from Task where ownerid=:userTask.id and status<>'Completed']; } } }

 

This doesn't run because the userTask variable is forgotten on the TaskList method.  I'd really appreciate any pointers here, as I'm obviously doing something basic wrong.

 

Thanks a lot!