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
mattdarnoldmattdarnold 

Visualforce: commandLink / param not working in dataTable

Hi - I am trying to create a simple visualforce page that displays a dataTable of opportunities and then provides a commandLink within each row that when clicked changes the Forecast_Category__c field to 'Medium'. This works, however, only for the final row of the dataTable. I also tried this using a pageBlockTable and it worked, but only for the first record.

Thanks for any help -- Matt

Here is my page:

Code:
<apex:page controller="forecastController" title="Forecast Report">

<apex:form id="theForm">
<apex:dataTable value="{!OppsHigh}" var="opp" id="theTable" cellpadding="4">
<apex:column >
<apex:facet name="header">Link</apex:facet>
<apex:commandLink action="{!updateOpp}" value="M" id="theCommandLink" rerender="theTable">
<apex:param value="{!opp.id}" assignTo="{!oppId}" />
</apex:commandLink>
</apex:column>
<apex:column >
<apex:facet name="header">Name</apex:facet>
<apex:outputText value="{!opp.name}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Forecast Category</apex:facet>
<apex:outputText value="{!opp.Forecast_Category__c}"/>
</apex:column>
</apex:dataTable>
</apex:form>

</apex:page>

 And, here is my controller:

Code:
public class forecastController {

public ID oppId;
public void setOppId(ID i) { oppId = i; }
public ID getOppId() { return oppId; }

public List<Opportunity> getOppsHigh() {
List<Opportunity> opps = [select
id,
name,
CloseDate,
Type,
Forecast_Category__c
from Opportunity
where Forecast_Category__c = 'High'];
return opps;
}

public void updateOpp() {
Opportunity opp = [select
id,
name,
CloseDate,
Type,
Forecast_Category__c
from Opportunity
where id =:oppId limit 1];

opp.Forecast_Category__c = 'Medium';
update opp;
}

}

 




Ron HessRon Hess
try these two changes

in the page
<apex:param value="{!opp.id}" name="oppId"  />


in the controller

[select     id, 
name,
CloseDate,
Type,
Forecast_Category__c
from Opportunity
where id =:ApexPages.currentPage().getParameters().get('oppId') limit 1]


also updateOpp() should return a pageReference, null is fine.
mattdarnoldmattdarnold
Thanks, Ron. That worked for all records on the page. It looks like I don't need the getter or setter either with this method since it is a page parameter. Is it actually possible to get this working without using a page parameter like I was attempting with the getter / setter for oppId?

-- Matt
Ron HessRon Hess
you would need one oppId var for each opp, and have these combined into a data model so that you have an oppid variable for each opp.
this method is simpler, for this case.
developingdeveloping

<tr>
            <td>
                Annualrevenue:<apex:outputtext value="{0,number, 000,000}">
                <apex:param value="{!value('123456789')}"/>
                </apex:outputtext>
            </td>
        </tr>

 

 

the above code working as per my requirement. but the below code not working, [accobject.annualrevenue__c] is my text field and i am giving the value 123456789, but i have to display that value  123,456,789

      <tr>
            <td>
                Annualrevenue:<apex:outputtext value="{0,number, 0,00}">
                <apex:param value="{!value(accobject.annualrevenue__c)}"/>
                </apex:outputtext>
            </td>
       </tr>

 

 

 

please anyone help me , how to display mytext field, in number format. my field should be text,