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
StephenJacobGoldbergStephenJacobGoldberg 

Visualforce Page list is returning the entire list instead of one value ...

I have a datatable and I am passing a list to the table all my other merge fields are displaying one value only but the Quantity field is displaying the whole list.  I am not sure why this is happening.  Thanks in advance.

 

Here is the relevant code from the controller class

 

 

public List<double> getQuantities(){
    List<Double> quantities = new List<Double>();
    for(QuoteLineItem qti :theLineItems){
       if(qti.Description.contains('Cage') ||    
                 qti.Description.contains('cage') ||   
                 qti.Description.contains('Private') || 
                 qti.Description.contains('private')){
            quantities.add(1);
				
        }
       else{
            quantities.add(qti.Quantity);
        }		
			
   }		
      return quantities;
}

 

 

the relevant code from the vforce page

 

 

<DIV width="100%"  style="background-color: #807F84; color: #FFFFFF;">Monthly Recurring Charges </DIV>
<apex:dataTable value="{!LineItems}" var="LIs" width="100%" border="1px" >
<apex:column headerValue="Line Item" value="{!LIs.Description}" headerClass="tableHead"/>
<apex:column headerValue="Quantity" value="{!Quantities}"/>
<apex:column headerValue="Unit Price" value="{!LIs.UnitPrice}"/>
<apex:column headerValue="MRC" value="{!LIs.Total_MRC__c}"/>
</apex:dataTable>
  
Best Answer chosen by Admin (Salesforce Developers) 
StephenJacobGoldbergStephenJacobGoldberg

Bob,

 

Thanks for the help ... I figured out how to solve it with what you said ... I broke it into three datatables, then put those inside a regular html table ... see code below:

 

 

 

<TABLE width="100%" border="0" cellpadding="0" cellspacing="0"> 
<TR>
<TD>
<apex:dataTable value="{!LineItems}" var="LIs" width="100%" border="1px" >
<apex:column headerValue="Line Item" value="{!LIs.Description}" headerClass="tableHead"/>
</apex:dataTable>
</TD>
<TD>
<apex:dataTable value="{!Quantities}" var="qs" width="100%" border="1px" >
<apex:column headerValue="Quantity" value="{!qs}"/>
</apex:dataTable>
</TD>
<TD>
<apex:dataTable value="{!LineItems}" var="LIs" width="100%" border="1px">
<apex:column headerValue="Square Feet" value="{!LIs.CUSF_Value__c}"/>
<apex:column headerValue="Kilowatt" value="{!LIs.CUSF_Value__c}"/>
<apex:column headerValue="Unit Price" value="{!LIs.UnitPrice}"/>
<apex:column headerValue="MRC" value="{!LIs.Total_MRC__c}"/>
</apex:dataTable>
</TD>
</TR>
</TABLE>

 

 

All Answers

bob_buzzardbob_buzzard

This is because the quantity column is displaying the returned value from the getQuantities method, which is a list.  Your other columns are displaying individual fields from Lls, which is iterating the LineItems list.

 

 

StephenJacobGoldbergStephenJacobGoldberg

Bob,

 

Thanks for responding.    I guess I am confused because they are both lists. Shouldn't it itterate throught the Quantities list? If not ... whats the best way to do this? 

 

Stephen

bob_buzzardbob_buzzard

Datatables can iterate lists, but columns can't I'm afraid.

 

In your datatable component you specify the value, which is the list to iterate, and the var, which is the element in the list currently being processed.  The markup inside the datatable is repeated for each element in the list.

 

For the column, you are passing a single value to it, so it does the best that it can which is to display the list.  

 

Can you post a bit more information about what you are trying to do - should there be a quantity associated with each line item or a number of quantities?

 

 

 

 

StephenJacobGoldbergStephenJacobGoldberg

Hi Bob,

 

 

I am listing out QuoteLineItems.    The problem is that my client uses Quantity for two different things.  Therefore when a QuoteLineItem is of a certain type they want Quantity to display as 1, otherwise they want Quantity to display as the actual quantity for the line item.   I am storing the quantities in a list, and replacing the quantities with 1 where appropriate, then passing that list.

 

 

StephenJacobGoldbergStephenJacobGoldberg

Bob,

 

Thanks for the help ... I figured out how to solve it with what you said ... I broke it into three datatables, then put those inside a regular html table ... see code below:

 

 

 

<TABLE width="100%" border="0" cellpadding="0" cellspacing="0"> 
<TR>
<TD>
<apex:dataTable value="{!LineItems}" var="LIs" width="100%" border="1px" >
<apex:column headerValue="Line Item" value="{!LIs.Description}" headerClass="tableHead"/>
</apex:dataTable>
</TD>
<TD>
<apex:dataTable value="{!Quantities}" var="qs" width="100%" border="1px" >
<apex:column headerValue="Quantity" value="{!qs}"/>
</apex:dataTable>
</TD>
<TD>
<apex:dataTable value="{!LineItems}" var="LIs" width="100%" border="1px">
<apex:column headerValue="Square Feet" value="{!LIs.CUSF_Value__c}"/>
<apex:column headerValue="Kilowatt" value="{!LIs.CUSF_Value__c}"/>
<apex:column headerValue="Unit Price" value="{!LIs.UnitPrice}"/>
<apex:column headerValue="MRC" value="{!LIs.Total_MRC__c}"/>
</apex:dataTable>
</TD>
</TR>
</TABLE>

 

 

This was selected as the best answer