+ Start a Discussion

Setters and/or passing value to the controller

I can't find the answer to this anywhere and its driving me crazy.
How can I pass a value into the controller?
<apex:pageBlock title="Lost Opportunites">
    <table width="100%" class="list">
        <tr class='headerRow'><th class='headerRow' scope="col" WIDTH="3%">Action</th><th class='headerRow' scope="col" WIDTH="25%">Opportunity Name</th><th class='headerRow' scope="col" WIDTH="25%">Stage</th><th class='headerRow' WIDTH="20%">Product</th><th class="headerRow"scope="col" align="right" width="8%">Net Line Item</th><th class='headerRow' scope="col" ALIGN="RIGHT" WIDTH="10%">Net Revenue</th></tr>
    <apex:repeat value="{!LostOpportunities}" var="aOpportunity">

            <td><apex:outputLink value="/{!aOpportunity.ID}/e"><b>Edit</b>
                <apex:param name="retURL" value="/{!id}"/>
            <td colspan="1"><apex:outputLink value="/{!aOpportunity.ID}">{!aOpportunity.Name}</apex:outputLink></td>
            <td colspan="3"><apex:outputText value="{!aOpportunity.StageName}"><apex:param assignTo="{!OppID}" value="{!aOpportunity.ID}"/></apex:outputText></td>
            <td align="right">{!aOpportunity.CurrencyIsoCode} {!aOpportunity.Sum_Net_Revenue__c}</td>
        <tr><td></td><td></td><td></td><td>{!OppID}</td><td align="right">00</td></tr>            
        <apex:repeat value="{!OpportunityLineItems}" var="aLineItem">
            <tr><td></td><td></td><td></td><td>{!aLineItem.PriceBookEntry.Name}</td><td align="right">{!aLineItem.revenue__c}</td></tr>    
    <table width="100%" class="list"><tr align="right"><td><b>Total {!LostTotal}</b></td></tr></table> 


 Ideally I want to pass a parameter using something like <apex:repeat value="{!OpportunityLineItems({!aOpportunity.ID})" var="aLineItem"> but it does not accept that if I add a parameter into the getter.
So then I created a String variable (OppID), with a getter and setter, and try to set it using the <apex:param .... > which is in the above code.  But the setter never gets called.....  I can only assume that the <apex:outputtext> does not support this command, but the documentation does not say anything.
How am I supposed to achieve what I am trying to do?  This is a related list on the accounts page.  The related list is showing Lost Opportunities.  For each Lost Opportunity I want to list each product.
Should I start again with an s-control??

Message Edited by GerhardNewman2 on 06-11-2008 07:17 AM

Message Edited by GerhardNewman2 on 06-11-2008 07:19 AM

Message Edited by GerhardNewman2 on 06-11-2008 07:20 AM
If you step back to what your actual goal is ("The related list is showing Lost Opportunities.  For each Lost Opportunity I want to list each product") I believe that the straightforward solution would be to
add a join from Opportunity to Product in the SOQL query you must already have in your controller. Once you have this hierarchical result set you can bind to anything in the tree via object dot notation.

The demo page (some of this would make a nice custom component BTW):
<apex:page controller="LostOppsDemo">
<apex:repeat var="opportunity" value="{!lostOpportunites}">
<apex:pageBlockTable var="line" value="{!opportunity.opportunityLineItems}" rendered="{!opportunity.hasOpportunityLineItem}">
<apex:column value="{!line.pricebookEntry.name}"/>
<apex:column value="{!line.quantity}"/>
<apex:column value="{!line.unitPrice}"/>
<apex:column value="{!line.totalPrice}"/>

The demo controller class:

public class LostOppsDemo {
public Opportunity[] getLostOpportunites() {
return [SELECT name, hasOpportunityLineItem, (SELECT quantity, unitPrice, totalPrice, pricebookEntry.name FROM opportunityLineItems) FROM Opportunity];


Message Edited by dchasman on 06-11-2008 11:35 AM
Excellent!  This has helped me solve my problem.  In my code I have kept both loops as repeats because I have no idea how the formatting can work correctly using a pageblocktable on the inner loop.  I display data from the opportunity level and from the opportunity line item level and your example was just showing the line items.

Can I assume that it's not possible to pass values to the controller like I was asking?
Can I also assume that apex:param does not work how I wanted?

I would like this clarified so I don't ever head off in that direction again.

Thanks very much for your help.

I would also like to know the answer to those last few questions.

I've got a similar need, but it's a case where I'm grouping records by a field value, as opposed to by a parent record.  So using subqueries won't help in my case.

My first thought was basically the same as the OP's (put everything inside a Repeat tag, pass the value of the var of the repeat in to the getter method in order to get the right data back.)  But like him, I can't see how to pass that param to the getter.

Thanks much!