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
John SmithJohn Smith 

Accessing Child object fields in VF page

Hey folks,

I'm trying to access the child object fields in the visual force page with standard controller as parent. In my case, parent object is student__c, child object is merchandise__c . I'm trying to access the price field in merchandise, But I'm getting the error "unknown property 'Student__cStandard controller.stud' ". Should i use both student and merchandise as standard controllers in VF page? Please guide me in this issue. 

 

CODE:

 

 

public with sharing class StudentController {
    
    public Student__c student; 
  
    private List<TimeVO> stud = Null; 
    public StudentController(apexpages.standardcontroller controller)
        
    {
        student= (Student__c) controller.getRecord();
    }
   
    
    public void TimeVO()
    {
    stud = [select ID,STUDENTNAME__C, (Select Price__c From Merchandise__r) from Student__C order by STUDENTNAME__C];
    }
    
    public List<TimeVO> getstud()
    {
    return stud;
    }
     
}

 

 

VF page:

 

 

<apex:page standardController="Student__c" extensions="StudentController" action="{!TimeVO}" >

    <apex:form >

    <apex:pageBlock title="StudentList" >    

    <apex:pageBlockSection >

 

       <apex:pageBlockTable value ="{!Stud}" var = "p">

        <apex:column headervalue="StudentName"><apex:outputLink value="/apex/StudentForm?id={!p.id}">{!p.StudentName__c}</apex:outputLink></apex:column>

        <apex:column headervalue="price">{!p.Price__c}</apex:column>

</apex:pageBlockTable>    

</apex:pageBlockSection>

 

 

    </apex:pageBlock>

        </apex:form>

</apex:page>

 

John SmithJohn Smith

I'm just pasting the sample code. i'm using the controller, because i have to write a business logic in the controller depending on the values of child object field. 

minkeshminkesh

Hello john,

                    you can not use multiple standardcontroller in VF page.you can use it page side. follow this link- http://boards.developerforce.com/t5/Visualforce-Development/Multiple-Standard-Controller/m-p/222839#M30515

try this code :-

 

public with sharing class StudentController {
    
    public Student__c student; 
  
    public List<TimeVO> stud{get;set;}
    public StudentController(apexpages.standardcontroller controller)
        
    {
        stud = new List<TimeVO>();
        student= (Student__c) controller.getRecord();
    }
   
    
    public void TimeVO()
    {
    stud = [select ID,STUDENTNAME__C, (Select Price__c From Merchandise__r) from Student__C order by       STUDENTNAME__C];
    }
    
    public List<TimeVO> getstud()
    {
    return stud;
    }
     
}

 

 

VF page:

 

 

<apex:page standardController="Student__c" extensions="StudentController" action="{!TimeVO}" >

    <apex:form >

    <apex:pageBlock title="StudentList" >    

    <apex:pageBlockSection >

 

       <apex:pageBlockTable value ="{!Stud}" var = "p">

        <apex:column headervalue="StudentName"><apex:outputLink value="/apex/StudentForm?id={!p.id}">{!p.StudentName__c}</apex:outputLink></apex:column>

        <apex:column headervalue="price">{!p.Price__c}</apex:column>

</apex:pageBlockTable>    

</apex:pageBlockSection>

 

 

    </apex:pageBlock>

        </apex:form>

</apex:page>