1

I am trying to have multiple text-boxes inside a table cell. I am creating the table using apex:repeat tag and the multiple text-boxes using another apex:repeat tag nested in the earlier one. The starts throwing Unknown property exception during saving of the file.

NOTE: It works fine, if the apex:inputText is changed to apex:outputText

Visualforce code -

<apex:page controller="MyPageController" showHeader="false" action="{!getData}">
  <apex:form>    
<table border="1">
        <thead>
            <tr>
                <th>Source Field</th>
                <th>Target Field</th>
            </tr>
        </thead>
        <tbody>
            <apex:repeat value="{!requestMappings}" var="mapp">
                <tr>
                    <td>
                        <apex:repeat value="{!mapp.SourceFields}" var="sfx">
                            <apex:inputText value="{!sfx}"/>
                        </apex:repeat>                      
                    </td>
                    <td>
                        <apex:inputText value="{!mapp.TargetField}"/>
                    </td>
                </tr>
            </apex:repeat>
        </tbody>
    </table>
</apex:form>
</apex:page>

Controller Code -

public with sharing class MyPageController {
    public List<Mapping> requestMappings {get; set;}

    //Inner Class for the Edit View
    public class Mapping implements Comparable {
        public List<String> SourceFields {get; set;}
        public String TargetField {get; set;}
        public Integer DisplayOrder {get; set;}

        public Integer compareTo(object o) {
            Mapping mapp = (Mapping) o; 
            if (this.DisplayOrder == mapp.DisplayOrder) return 0;
            if (this.DisplayOrder >  mapp.DisplayOrder) return 1;
            return -1;
        }
    }

    public void getData() {
        this.requestMappings = new List<Mapping>();
        Mapping mapp = new Mapping();
        mapp.SourceFields = new List<String>{'New Field 1','New Field 2'};
        mapp.DisplayOrder = this.requestMappings.size();
        mapp.DisplayOrder++;
        this.requestMappings.add(mapp);
    }
}

Exception -

Save error: Unknown property 'sfx'  MyPage.page /dev29/src/pages    line 1  Force.com save problem

2 Answers 2

0

One mechanism you can use to work around this behavior is to create a class to represent the SourceField data and bind to a single string property on that instance instead of trying to bind to an instance of a string contained in a list.

Page Controller

public with sharing class MyPageController {
    public List<Mapping> requestMappings {get; set;}

    //Inner Class for the Edit View
    public class Mapping implements Comparable {
        public List<SourceField> SourceFields {get; set;}
        public String TargetField {get; set;}
        public Integer DisplayOrder {get; set;}

        public Integer compareTo(object o) {
            Mapping mapp = (Mapping) o; 
            if (this.DisplayOrder == mapp.DisplayOrder) return 0;
            if (this.DisplayOrder >  mapp.DisplayOrder) return 1;
            return -1;
        }
    }

    public class SourceField {
        public string FieldName { get; set; }
        public SourceField(String name) {
            this.FieldName = name;
        }
    }

    public void getData() {
        this.requestMappings = new List<Mapping>();
        Mapping mapp = new Mapping();
        mapp.SourceFields = new List<SourceField>();
        mapp.SourceFields.add(new SourceField('New Field 1'));
        mapp.SourceFields.add(new SourceField('New Field 2'));
        mapp.DisplayOrder = this.requestMappings.size();
        mapp.DisplayOrder++;
        this.requestMappings.add(mapp);
    }

} 

VF Markup

<apex:page controller="MyPageController" showHeader="false" action="{!getData}">
     <apex:form>    
       <table border="1">
        <thead>
            <tr>
                <th>Source Field</th>
                <th>Target Field</th>
            </tr>
        </thead>
        <tbody>
            <apex:repeat value="{!requestMappings}" var="mapp">
                <tr>
                    <td>
                        <apex:repeat value="{!mapp.SourceFields}" var="sfx">
                            <apex:inputText value="{!sfx.FieldName}" />
                        </apex:repeat>                      
                    </td>
                    <td>
                        <apex:inputText value="{!mapp.TargetField}"/>
                    </td>
                </tr>
            </apex:repeat>
        </tbody>
    </table>
</apex:form>
</apex:page>
1
  • Thanks @Mark. Yes the wrapper works. I also figured it out just now :)
    – Tilak De
    Jun 24, 2015 at 17:51
0

Solution - Create another wrapper class around the String field and then create a list of the wrapper class.

Controller -

public with sharing class MyPageController {
    public List<Mapping> requestMappings {get; set;}

    //Inner Class for the Edit View
    public class Mapping implements Comparable {
        public List<StringField> SourceFields {get; set;}
        public String TargetField {get; set;}
        public Integer DisplayOrder {get; set;}

        public Integer compareTo(object o) {
            Mapping mapp = (Mapping) o; 
            if (this.DisplayOrder == mapp.DisplayOrder) return 0;
            if (this.DisplayOrder >  mapp.DisplayOrder) return 1;
            return -1;
        }
    }

    public class StringField {
        public String field {get; set;}
    }

    public void getData() {
        this.requestMappings = new List<Mapping>();
        Mapping mapp = new Mapping();
        mapp.SourceFields = new List<StringField>();
        StringField sf = new StringField();
        sf.field = 'New Field 1';
        mapp.SourceFields.add(sf);
        sf = new StringField();
        sf.field = 'New Field 2';
        mapp.SourceFields.add(sf);
        mapp.DisplayOrder = this.requestMappings.size();
        mapp.DisplayOrder++;
        this.requestMappings.add(mapp);
    }
}

Visualforce -

<apex:page controller="MyPageController" showHeader="false"
    action="{!getData}">
    <apex:form>
        <table border="1">
            <thead>
                <tr>
                    <th>Source Field</th>
                    <th>Target Field</th>
                </tr>
            </thead>
            <tbody>
                <apex:repeat value="{!requestMappings}" var="mapp">
                    <tr>
                        <td><apex:repeat value="{!mapp.SourceFields}" var="sfx">
                                <apex:inputText value="{!sfx.field}" />
                            </apex:repeat></td>
                        <td><apex:inputText value="{!mapp.TargetField}" /></td>
                    </tr>
                </apex:repeat>
            </tbody>
        </table>

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .