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
AlbertoSMAlbertoSM 

Help with a Visualforce Page

Hi everyone

I'm witting one of my first Visualforces.This one:
<apex:page Controller="ScenariosController">
    <apex:pageMessages ></apex:pageMessages>
    <apex:pageBlock >
    
        <apex:pageBlockTable value="{!}" var="item" >
    
             <apex:column value="{!item.Scenario__c}"                 style="background-color:{!If(item.CHK_Scenario_Principal__c ==True,'#beecf4', '')}"/>
            <apex:column value="{!item.PCK_Tower_Height__c}"         style="background-color:{!If(item.CHK_Scenario_Principal__c ==True,'#beecf4', '')}" />
            <apex:column value="{!item.NUM_Quantity__c}"             style="background-color:{!If(item.CHK_Scenario_Principal__c ==True,'#beecf4', '')}" />
            <apex:column value="{!item.CHK_Scenario_Principal__c}"   style="background-color:{!If(item.CHK_Scenario_Principal__c ==True,'#beecf4', '')}"/>
            <!-- background-color:{!If(opp.StageName =='Negotiation/Review','#7CFC00',If(opp.StageName =='Closed Won','#DEB887','#DC143C'))}; -->
    
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>


And this controller:
 
public class ScenariosController{
      
    List<Quote_line__c> quoteLineList;
    
    //Populate a list with all the quote Lines != NULL ordered by NUM_Scenario__c DESC
    public List<Quote_line__c> getQuoteLineItems(){
       Id budgetId= ApexPages.currentPage().getParameters().get('Id');
       if (budgetId!= NULL){
           List<Quote_line__c> quoteLineList = new List<Quote_line__c>();
           quoteLineList = [SELECT id,name,lkp_product__r.family__c, lkp_product__r.Nominal_Power_MW__c, CHK_Included__c,
                                        NUM_Cost__c,LKP_Configurator__c,Sum_mandatory_fields_for_budReq_unfill__C,Date_from__c,Date_to__c,
                                        TXT_Tower_First_Value__c, NUM_Quantity__c,LKP_Product__c,MD_quote__c, NUM_Scenario__c, CHK_Scenario_Principal__c
                             FROM quote_line__c 
                             WHERE NUM_Scenario__c != NULL
                             ORDER BY NUM_Scenario__c
                             DESC];
                           }
        return quoteLineList;
    }
}



I don't know how to continue. What I know is, I have to define the get method to pass data from the controller to the Visualforce but no idea about where and how to put it.

Thanks in advance for your time!
Cheers!
Alberto
Jeremy DeseezJeremy Deseez
Hello,
You have to do something like this :
public List<Quote_line__c> quoteLineList {get;set;}

instead of this : 
List<Quote_line__c> quoteLineList;
Ashish DevAshish Dev
Hi Alberto,

Actually there are 2 issues in your code. 
1) in VF page - To get data from controller in VF you need to call method getQuoteLineItems without 'get' word. So the correct statement will be.
line #5 ->  
<apex:pageBlockTable value="{!quoteLineItems}" var="item" >
2) In your controller you are declaring variable quoteLineList 2 times first at line  #3 and then at line #9.
in your case it does not impact but it is not good practice, so just user another name of the variable in your method.


Let me know if it helps you.
AlbertoSMAlbertoSM
Hi Ashish Dev,
Wth your suggestions:
public class ScenariosController{
    
    List<Quote_line__c> quoteLineList;
    
    //Populate a list with all the quote Lines != NULL ordered by NUM_Scenario__c DESC
    public List<Quote_line__c> getQuoteLineItems(){
       List<Quote_line__c> getQuoteLineList = new List<Quote_line__c>();
       Id budgetId= ApexPages.currentPage().getParameters().get('Id');
       if (budgetId!= NULL){
           getQuoteLineList = [SELECT id,name,lkp_product__r.family__c, lkp_product__r.Nominal_Power_MW__c,                                       CHK_Included__c,NUM_Cost__c,LKP_Configurator__c,Sum_mandatory_fields_for_budReq_unfill__C,
Date_from__c,Date_to__c,TXT_Tower_First_Value__c, NUM_Quantity__c,LKP_Product__c,MD_quote__c, 
NUM_Scenario__c, CHK_Scenario_Principal__c
                               FROM quote_line__c 
                               WHERE NUM_Scenario__c != NULL
                               ORDER BY NUM_Scenario__c
                               DESC];
                           }
        return getQuoteLineList;
    }  
}

and the visualforce:
<apex:page Controller="ScenariosController">
    <apex:pageMessages ></apex:pageMessages>
    <apex:pageBlock >
    
        <apex:pageBlockTable value="{!QuoteLineItems}" var="item" >
    
             <apex:column value="{!item.NUM_Scenario__c}"                 style="background-color:{!If(item.CHK_Scenario_Principal__c ==True,'#beecf4', '')}"/>
             
             <apex:column headerValue="{!$ObjectType.Scenario__c.fields.name.Label}"  style="background-color:{!If(item.CHK_Scenario_Principal__c ==True,'#beecf4', '')}" >
                <apex:outputLink value="/{!item.name}" target="_blank" >{!item.name}</apex:outputLink>
            </apex:column>
             
            <apex:column value="{!item.TXT_Tower_First_Value__c}"         style="background-color:{!If(item.CHK_Scenario_Principal__c ==True,'#beecf4', '')}" />
            <apex:column value="{!item.NUM_Quantity__c}"             style="background-color:{!If(item.CHK_Scenario_Principal__c ==True,'#beecf4', '')}" />
            <apex:column value="{!item.CHK_Scenario_Principal__c}"   style="background-color:{!If(item.CHK_Scenario_Principal__c ==True,'#beecf4', '')}"/>
            <!-- background-color:{!If(opp.StageName =='Negotiation/Review','#7CFC00',If(opp.StageName =='Closed Won','#DEB887','#DC143C'))}; -->
    
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>

Now the VF is showed but it's empty. It seems it doesn't get the data from the controller. There is something wrong in the controller, but I cannot find it.
Thanks!!
Cheers!
Alberto
 
MatsMats

In the controller you need the following line at the top (as Jeremy wrote above) then you set its value in the code below.

 

public class ScenariosController{
public List<Quote_line__c> quoteLineList {get;set;}

// Then later on you refer to that list

QuoteLineItems(){

       quoteLineList = new List<Quote_line__c>();
       Id budgetId= ....
	.
	.
	.
	}
}