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
cmtgolf05cmtgolf05 

Displaying custom variable in PageBlockTable

I have created a custom variable from a query on my controller. I am now trying to display this variable on the Apex page in a pageBlockTable. Here is my code:

 

Apex Page:

 

<apex:page controller="groupbytestcontroller">

<apex:form >

<apex:pageBlock title="" id="pageBlock">
<apex:pageBlockTable value="{!XXX}" var="summary">
<apex:column Headervalue="Sum Refund" >
<apex:outputText value="{!sumrefund}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>


</apex:form>

Sum Refund is <apex:outputText value=" {!sumrefund}"/>

</apex:page>

 

Controller:

public with sharing class groupbytestcontroller {

public decimal sumrefund { get; private set; }

List<Refunds__c> myRNDS;
public List<Refunds__c> getXXX() {

AggregateResult[] myRNDS = [Select SUM(Total_Refund__c)xx From Refunds__c Where OppLineItem_Id__c = '00ka000000iBrhG' ];

for (AggregateResult cus:myRNDS){

sumrefund = (Decimal) cus.get('xx');


system.debug('SUM Refund Is '+ sumrefund);

}
return null;
}

}

 

As you can see on the apex page I try to call the variable sumrefund two times. One inside of the pageblock table and one outside of the table. The one outside of the table/form works and displays the correct value. However the one inside the table does not display anything. Also if is substute the collumn headervalue with the variable it will show there as well, it just will not show in its collumn.

 

Any help?

Gaurish Gopal GoelGaurish Gopal Goel

In the getXXX() method you should return List<Refund__c> so that on the vf page there will be a list in the Value={!XXX} and then use the variable of the pageblocktable with dot operator to display any column value present in your list returned by the controller.

 

For Example:

 

PAGE CODE-

<apex:pageBlockTable value="{!list_accounts}" var="acc">
<apex:column Headervalue="Account Name" >
<apex:outputText value="{!acc.name}"/>
</apex:column>
</apex:pageBlockTable>

 

CLASS CODE-

public List<Account> list_accounts{get;set;}

 

public constructor()

{

list_accounts = [select id,name from account limit 10];

}

 

// Ten records of Account will be returned to VF Page and by using the variale of the pageblocktable you can display each and every record present in your list.

cmtgolf05cmtgolf05

Thank you for your reply however the AggregateResult is very key to this query and I am setting the value of the SUM(Total_Refund__c) to the variable 'sumrefund" and I want to call the variable in a pageblocktable.

 

Thank you,