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
cedgcedg 

Error: Unknown property in VFpage with custom controller

I'm becoming mad with this error. I checked the similar post . In those i see the error and in my code i don't see anything wrong.

 

Error is :  Error: Unknown property 'CO01_RegSport_Data.RegistrationChild.indexChild' 

 

The VF page is :

<apex:pageBlockTable value="{!data.regChildren}" var="child">
	<apex:column >
		<apex:facet name="header">number</apex:facet>
		<apex:outputText value="{!child.indexChild}" />
	</apex:column>
	<apex:column >
		<apex:facet name="header">{!labels.FirstName__c}</apex:facet>
		<apex:inputField value="{!child.reg.Firstname__c}" />
	</apex:column>
</apex:pageBlockTable>

 {!child.reg.Firstname__c} is working fine, but not {!child.indexChild}

 

and the controller is :

public class CO01_RegSport_Data{

    private Registration__c regMain;
    private List<RegistrationChild> regChildren;


    public CO01_RegSport_Data(String userId, CO01_RegSport mainclass){
        ...
    }
	

    public Registration__c getRegMain(){return regMain;}
    public List<RegistrationChild> getRegChildren(){return regChildren;}
   
    public PageReference addRegistrationChild(){
        if (regChildren == null) regChildren = new List<RegistrationChild>();
        regChildren.add(new RegistrationChild(regMain, 'Child', this, empl, regChildren.size()+1));
        return null;
    }

    public class RegistrationChild{
        private Registration__c reg;
        private Registration__c regParent;
        private CO01_RegSport_Data data;
        private Employee__c empl;
		private Integer indexChild;

        public RegistrationChild(Registration__c regParent, String relation, CO01_RegSport_Data data, Employee__c empl, Integer indexChild){
            
            reg = new Registration__c();
            ...
			this.indexChild = Integer.valueOf(indexChild);
        }

        public Integer getIndexChild(){return indexChild;}
        public Registration__c getReg(){return reg;}
    }

}

 

Please help me. Tnx in advance.

Best Answer chosen by Admin (Salesforce Developers) 
ColinKenworthy2ColinKenworthy2

From your sample code I created a Registration__c custom object with field Firstname__c, 2 classes and a VF page and it compiles fine. I run the page [salesforce.com/apex/RegSport] and I see a '1' and the name 'Bill' in a table.

[Note: I had to remove references to Employee__c since theres no clue as to what it is, and I initialised regChildren with 1 row]

 

VF page

<apex:page  controller="CO01_RegSport">
<apex:form>
<apex:pageBlock>

        <apex:pageBlockTable value="{!data.regChildren}" var="child">
            <apex:column >
                <apex:facet name="header">number</apex:facet>
                <apex:outputText value="{!child.indexChild}" />
            </apex:column>
            <apex:column >
                <apex:facet name="header">First Name</apex:facet>
                <apex:inputField value="{!child.reg.Firstname__c}" />
            </apex:column>
        </apex:pageBlockTable>

</apex:pageBlock>
</apex:form>
</apex:page>

 

Class

public class CO01_RegSport_Data{

    private Registration__c regMain;
    private List<RegistrationChild> regChildren;


    public CO01_RegSport_Data(CO01_RegSport mainclass){
//        ...
        regMain = new Registration__c(Firstname__c='Colin');
        addRegistrationChild();
    }
    

    public Registration__c getRegMain(){return regMain;}
    public List<RegistrationChild> getRegChildren(){return regChildren;}
   
    public PageReference addRegistrationChild(){
        if (regChildren == null) regChildren = new List<RegistrationChild>();
        regChildren.add(new RegistrationChild(regMain, 'Child', this, regChildren.size()+1));
        return null;
    }

    public class RegistrationChild{
        private Registration__c reg;
        private Registration__c regParent;
        private CO01_RegSport_Data data;
        private Integer indexChild;

        public RegistrationChild(Registration__c regParent, String relation, CO01_RegSport_Data data, Integer indexChild){
            
            reg = new Registration__c(Firstname__c='Bill');
//            ...
            this.indexChild = Integer.valueOf(indexChild);
        }

        public Integer getIndexChild(){return indexChild;}
        public Registration__c getReg(){return reg;}
    }

}

 

Class

public class CO01_RegSport{

    public CO01_RegSport_Data data {get; set;}
//    ...
    
    public CO01_RegSport(){
//        ...
        regSportInit();
    }

    public void regSportInit() {//separate function only because otherwize it cannot be tested (ApexPages.currentPage() not available in test function)
//        ...
        data = new CO01_RegSport_Data(this);
//        ...
    }
}

 

All Answers

ColinKenworthy2ColinKenworthy2

What does data refer to in this line ?  Could you remove it ? {!regChildren} would work I think (from your code snippet).

<apex:pageBlockTable value="{!data.regChildren}" var="child">

 

cedgcedg

sorry, i forgot to mention :

 

the real controller is the class CO01_RegSport which instantiates the class CO01_RegSport_Data

 

public class CO01_RegSport{

    private CO01_RegSport_Data data;
    ...
    
	public CO01_RegSport(){
        ...
        regSportInit();
    }

    public void regSportInit() {//separate function only because otherwize it cannot be tested (ApexPages.currentPage() not available in test function)
		...
        data = new CO01_RegSport_Data(emplid, this);
		...
    }
}

 

so, {!data....} shouldn't be the problem as i use it for all other fields.

ColinKenworthy2ColinKenworthy2

If you comment out that first  visualforce column does it give a similar error about Firstname__c ?

I'm wondering if its a visibility issue with the inner class.

cedgcedg

if i comment the first column, i've no error, it's working fine but i need this index.

 

In fact the original problem is i would like to know the index of a each row of the table so as to use in some JS.

So i put the indexChild as a property buty i can't reach it while i can reach the other properties.

ColinKenworthy2ColinKenworthy2

perhaps try this approach

public Integer counter { get; set; }

 or would this work for you:

http://blog.jeffdouglas.com/2010/04/02/visualforce-row-counter-for-iteration-components/

cedgcedg

I checked the example of Jeff Douglas and i think it's the same.

 

his class "DataTableWrapper"  corresponds to my class "RegistrationChild"

his "counter" is my "indexChild"

cedgcedg

a stupid question : i replaced 

private Registration__c reg;
public Registration__c getReg(){return reg;}

 by 

private Registration__c reg{get;set;}

 and now i've error in the class CO01_RegSport when calling data.someitem.getReg().Lastname__c  (Method does not exist or incorrect signature:)

 

I'm new in Apex dev, but it's the same isn't it ???

ColinKenworthy2ColinKenworthy2

It might need to be public, not private.

ColinKenworthy2ColinKenworthy2

I think you'll need to recompile (save) both classes.

ColinKenworthy2ColinKenworthy2

From your sample code I created a Registration__c custom object with field Firstname__c, 2 classes and a VF page and it compiles fine. I run the page [salesforce.com/apex/RegSport] and I see a '1' and the name 'Bill' in a table.

[Note: I had to remove references to Employee__c since theres no clue as to what it is, and I initialised regChildren with 1 row]

 

VF page

<apex:page  controller="CO01_RegSport">
<apex:form>
<apex:pageBlock>

        <apex:pageBlockTable value="{!data.regChildren}" var="child">
            <apex:column >
                <apex:facet name="header">number</apex:facet>
                <apex:outputText value="{!child.indexChild}" />
            </apex:column>
            <apex:column >
                <apex:facet name="header">First Name</apex:facet>
                <apex:inputField value="{!child.reg.Firstname__c}" />
            </apex:column>
        </apex:pageBlockTable>

</apex:pageBlock>
</apex:form>
</apex:page>

 

Class

public class CO01_RegSport_Data{

    private Registration__c regMain;
    private List<RegistrationChild> regChildren;


    public CO01_RegSport_Data(CO01_RegSport mainclass){
//        ...
        regMain = new Registration__c(Firstname__c='Colin');
        addRegistrationChild();
    }
    

    public Registration__c getRegMain(){return regMain;}
    public List<RegistrationChild> getRegChildren(){return regChildren;}
   
    public PageReference addRegistrationChild(){
        if (regChildren == null) regChildren = new List<RegistrationChild>();
        regChildren.add(new RegistrationChild(regMain, 'Child', this, regChildren.size()+1));
        return null;
    }

    public class RegistrationChild{
        private Registration__c reg;
        private Registration__c regParent;
        private CO01_RegSport_Data data;
        private Integer indexChild;

        public RegistrationChild(Registration__c regParent, String relation, CO01_RegSport_Data data, Integer indexChild){
            
            reg = new Registration__c(Firstname__c='Bill');
//            ...
            this.indexChild = Integer.valueOf(indexChild);
        }

        public Integer getIndexChild(){return indexChild;}
        public Registration__c getReg(){return reg;}
    }

}

 

Class

public class CO01_RegSport{

    public CO01_RegSport_Data data {get; set;}
//    ...
    
    public CO01_RegSport(){
//        ...
        regSportInit();
    }

    public void regSportInit() {//separate function only because otherwize it cannot be tested (ApexPages.currentPage() not available in test function)
//        ...
        data = new CO01_RegSport_Data(this);
//        ...
    }
}

 

This was selected as the best answer
cedgcedg

indeed , by deploying with Eclipse,it's working. I was changing directly in salesforce ...

 

Thanks for your help and your time, Colin