You need to sign in to do that
Don't have an account?
miko Lee
How to pass value from controller to apex:component which the apex:component is put in a VF page.
// Controller public with sharing class FTG_QB_ResultsController{ public List<FTG_QB_Results__c> viewResInfo {get; set;} public void gradeRecordMethod(){ viewResInfo = [SELECT Id, Name, Date_Taken__c, FROM FTG_QB_Results__c LIMIT 10 ] ; }
<!--Page--> <apex:page controller="FTG_QB_ResultsController" showHeader="false" sidebar="false"> <apex:form > <c:FTG_QB_Grade_Results / > <apex:form> </apex:page>
<!--Copmponent--> <apex:component controller="FTG_QB_ResultsController" > <apex:pageBlock title="Grade and Result" > <h3>Hello, {!$User.FirstName} {!$User.LastName}</h3> <apex:outputText value="{!viewResInfo[0].Name}"/> </apex:pageBlock> </apex:component>How can I pass value from controller to component? I cannot get the outputText in the page. But if i did not use apex:component and put the content of component in apex:page. It can get the viewResInfo and display the value. How to solve it to pass value from controller to component?
I have made a minor change to include a contructor.
Let me know if this helps.
HI LBK,
I got use this way before and I know it work.... But what I want to know is can I still put viewResInfo in function and pass the value from the function to component? It is possible?
Thanks.
Your problem is not whether you are displaying the data inside a component or in the page itself.
Your method gradeRecordMethod() is not called even once, to build the viewResInfo list.
if you want this list to be built on page load, you need to call it within the consructor.
If you don't want to use a constructor for some reason, you can call it using apex:page action attribute.
Let me know if this helps.
Hi LBK,
I try to put <apex:page> in the component but it show that <apex:page> cannot be used inside <apex:component>. Hence, I not sure how to call the function in the <apex:component>.
Actually my page still got some code. When it press View Link, it will link to component and showGradeResult.
Then the controller will SELECT the field only WHERE Exam_id__r.Id =:getExamResultId. If i put viewResInfo in constructor, then getExamResultId cannot run . So how should I pass the function instead of using <apex:page action="{!gradeRecordMethod}">