You need to sign in to do that
Don't have an account?
Passing data to Visualforce page
I have a class that stores data from a custom object into a List. The class sorts the list and does all the things it needs to do, but now I want to pass the data back to my visualforce page.
But! I dont want to use pageblock or tabledata to render the values. Everytime I reference my class, it errors out on me. Here is some code:
First method in my class that is getting the data:
public class getOnboarding { public getOnboarding(ApexPages.StandardController Controller){ } public SFDC_Acct_Plan__c[] getPlanInfo(){ List<SFDC_Acct_Plan__c> fields = new List<SFDC_Acct_Plan__c>(); fields = [SELECT Planning_Year__c, Sales_Agreement_in_Place__c, Plan_Status__c, Last_Plan_Revision__c, Days_Between__c, Non_Disclosure_Agreement_in_Place__c, Number_of_assets_tracked__c, On_Boarding_Packet_to_Customer__c, Kickoff_Meeting_Completed__c, Kickoff_Meeting_Completed_on__c FROM SFDC_Acct_Plan__c WHERE Account__c IN (SELECT AccountId FROM AccountShare WHERE UserOrGroupId=:Userinfo.getUserId()) AND (Plan_Status__c = 'Draft') ]; return fields; }
and I want to pass it to my VF page:
<apex:page showHeader="false" sidebar="false" standardController="SFDC_Acct_Plan__c" extensions="getOnboarding"> <!-- --------------------------------------- --> <!-- ------------START OF STYLES------------ --> <!-- --------------------------------------- --> <style> #onboardingStages {text-align: center; width:95%} .pbheader {background-color:#000000!important; color:#FF4D4D!important;} .pbsubheader {background-color:#FFFF85!important; color:#5a5a5a!important;} </style> <!-- --------------------------------------- --> <!-- ------------ END OF STYLES ------------ --> <!-- --------------------------------------- --> <h1>Welcome Back {!$User.FirstName}</h1><br/> <h2>Date: {!MONTH(TODAY())}/{!DAY(TODAY())}/{!YEAR(TODAY())}</h2> <div id="onboardingStages"> <apex:variable var="stage" value="{!StageImage}"/> <apex:image url="{!URLFOR($Resource.Stages, stage)}" /> </div>
But I want to put the data into my own table.
If I reference my method {!PlanInfo.Plan_Status__c} it will not allow me to use the data (unless its in a pageBlock). I have also tried using variables for this.
I basically want to pass it to an HTML table cell that I define later.
Anyone come across this before? I know its something easy and silly ... but I cant get it.
Thank you,
TS
You need to iterate over the list.
Use an apex:repeat tag and define your html elements inside the tag. Apex:repeat will allow you to iterate over the list and reuse the HTML tags nested inside of it.
All Answers
You need to iterate over the list.
Use an apex:repeat tag and define your html elements inside the tag. Apex:repeat will allow you to iterate over the list and reuse the HTML tags nested inside of it.
YES!!!!
Thank you!
Something so simple, but couldnt find documentation anywhere. Silly, I know, I wish there were better repositories for this kind of information!
<apex:reapeat value={!yourMethodHere} var="yourVariableHere">
<h1>{!yourVariableHere.}</h1>
</apex:repeat>
I cannot seem to get this to work however if my Apex Class is storing more than one thing in the list.
Right now I have a List on my custom object pulling data from 10 fields. I cannot reference them.
Normally it would be like this:
<apex:column value="{!pi.Plan_Status__c}" headerValue="Status" width="33%" />
But using the apex:repeat, it will not allow me to reference the individiual field.
<apex:repeat value="{!PlanInfo}" var="pi">
<apex:outputText><p>{!pi.Plan_Status__c}</p></apex:outputText>
<apex:outputText><p>{!pi.Plan_Start_Date__c}</p></apex:outputText>
</apex:repeat>
It doesnt cause an error, it just doesnt show the value of my fields.
For some reason, this works now.
Perhaps I just needed to let my computer think about its terrible behaviour lately. It seems to have corrected itself, overnight, with no changes made to it.
I am so glad I banged my head for hours yesterday trying to figure out how to fix something that wasn't even broke.