+ Start a Discussion
Arup SarkarArup Sarkar 

Error: Unknown property 'String.label'

Hi I am getting the following error in Visualforce, I would really appreciate if someone can help me resolve it. I have also attached the apex class.



ErrorError: Unknown property 'String.label'

 

The error is in the tag

<h2>{!caseField.label}</h2><br/>

 

Visualforce page:

=============

<apex:page standardController="Case" extensions="dynamicCaseRecord">
    <apex:form >
        <apex:repeat var="caseField" value="{!caseFieldList}" >
            <h2>{!caseField.label}</h2><br/>
            <apex:inputText value="{!dynamicCase[caseField]}" 
                        rendered="{!IF(contains(caseField, "Contact"), true, false)}"/>
            <apex:outputText value="{!dynamicCase[caseField]}" 
                        rendered="{!IF(contains(caseField, "Contact"), false, true)}"/>
            <br/><br />
        </apex:repeat>
    </apex:form>
</apex:page>

 

Apex Class:

=============

public class dynamicCaseRecord {
    // construct a SOQL call that populates the case with values from the record  
    
    public dynamicCaseRecord(ApexPages.StandardController controller) {
        String qid = ApexPages.currentPage().getParameters().get('id');
        dynamicCase = [select id, Contact.Name,
        Contact.Email, Contact.Phone, CaseNumber, Origin, Status from Case where id= :qid];
    }

    // create a list of fields that will be rendered on the Visualforce page  
    
    public List<String> caseFieldList { 
        get {
            if (caseFieldList == null) {
                caseFieldList = new List<String>();
                caseFieldList.add('Contact.Name');
                caseFieldList.add('Contact.Email');
                caseFieldList.add('Contact.Phone');
                caseFieldList.add('CaseNumber');
                caseFieldList.add('Origin');
                caseFieldList.add('Status');
             }
        return caseFieldList;
        }
        private set;
        }

    public final Case dynamicCase {get; private set; }
}

 

aballardaballard

Your caseFieldList property is just returning a list of strings, so the error message is correct.  Strings do not have a label property.

 

If you use a fieldset to contain the fields to be displayed, rather than building a list of strings via controller code, you can get the label automatically because fieldsets are a list of objects with label and fieldname properties. 

 

If you need to build the list of fieldnames via code like this, you will have to also build a list of the corresponding field labels. 

Shashikant SharmaShashikant Sharma

You need to do it differently using map

public class dynamicCaseRecord {
    // construct a SOQL call that populates the case with values from the record  
    
    public dynamicCaseRecord(ApexPages.StandardController controller) {
        String qid = ApexPages.currentPage().getParameters().get('id');
        dynamicCase = [select id, Contact.Name,
        Contact.Email, Contact.Phone, CaseNumber, Origin, Status from Case where id= :qid];
    }

    // create a list of fields that will be rendered on the Visualforce page  
    
    public MAP<String , String> caseFieldListMAP { 
        get {
            if (caseFieldListMAP == null) {
                caseFieldListMAP = new Map<String , String>();
                caseFieldListMAP.put('Contact.Name' , 'Name');
                caseFieldListMAP.put('Contact.Email' , 'Email');
                caseFieldListMAP.put('Contact.Phone' , 'Phone');
                caseFieldListMAP.put('CaseNumber' , 'CaseNumber');
                caseFieldListMAP.put('Origin' , 'Origin');
                caseFieldListMAP.put('Status', 'Status');
             }
        return caseFieldListMAP;
        }

    public List<String> caseFieldList { 
        get {
            if (caseFieldList == null) {
                caseFieldList = new List<String>();
                caseFieldList.add('Contact.Name');
                caseFieldList.add('Contact.Email');
                caseFieldList.add('Contact.Phone');
                caseFieldList.add('CaseNumber');
                caseFieldList.add('Origin');
                caseFieldList.add('Status');
             }
        return caseFieldList;
        }
        private set;
        }

    public final Case dynamicCase {get; private set; }
}

 Use this map in VFP

 

Get Labels from Object MAP Useing value from caseFieldMAP.

 

 

Ankit AroraAnkit Arora

As the error is in line <h2>{!caseField.label}</h2><br/>

 

So I believe that there is nothing to do with map. Just want to know what exactly you want to show here.As "caseFieldList" is the list of string and you want to show the value from list then you can do something like this :

 

<h2>{!caseField}</h2><br/>

 

It will display the Label from the list.

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page