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
Artem Kalus 7Artem Kalus 7 

Actions not working when SelectList is inside pageBlockTable or Repeat

SelectList put in table or repeat visualforce elements causes all controller methods to break. No errors are shown, however, the debug statements for methods that are called from the page are not showing. No javascript errors either.

When select list is substituted with any other element the row is successfuly added to the table, but when SelectList is there and it is not blank the new row is not added as well as other butons do not work on the page.

VFP:
<apex:page controller="Test_Ctr">
    <apex:form id="theForm">
        <apex:pageBlock title="Filters">
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton action="{!newFilter}" value="New Filter" rerender="theForm"/>
                <apex:commandButton action="{!testValues}" value="Test Values" rerender="theForm"/>
            </apex:pageBlockButtons>
            
            <apex:pageBlockTable value="{!ftsWrap}" var="row">
                <apex:column> 
                    <!--apex:selectList value="{!row.fieldvar}" size="1">
                        <apex:selectOptions value="{!listOptions}"/>
                    </apex:selectList-->
                    <apex:selectList value="{!row.fieldvar}" size="1" >
                        <apex:actionSupport event="onchange" reRender="theForm"/>
                        <apex:selectOptions value="{!listOptions}"></apex:selectOptions>
                    </apex:selectList>
                </apex:column>
            </apex:pageBlockTable>
            
            
        </apex:pageBlock>
    </apex:form>
</apex:page>

CTR:
public with sharing class Test_Ctr {
    
    
    public List <filtersWrap> ftsWrap {get;set;}
    public List <SelectOption> listOptions {get;set;}
    
    
    public Test_Ctr(){
        System.debug('*****Test_Ctr()');
        
        ftsWrap = new List <filtersWrap> ();
        //filtersWrap fw = new filtersWrap();
        //ftsWrap.add(fw);
        newFilter();
        
        listOptions = objectFieldsGetter();
        System.debug('ftsWrap: '+ftsWrap);
    }
    
    
    public List<SelectOption> objectFieldsGetter() 
    {
        String selectedObject = 'Task';
        
        Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
        Schema.SObjectType ObjectSchema = schemaMap.get(selectedObject);
        Map<String, Schema.SObjectField> fieldMap = ObjectSchema.getDescribe().fields.getMap();
        List<SelectOption> fieldNames = new List<SelectOption>();
        for (String fieldName: fieldMap.keySet()) 
        {  
            fieldNames.add(new SelectOption(fieldName,fieldName));
        }
        return fieldNames;
    }
    
    
    public class filtersWrap{
        public SelectOption fieldvar {get;set;}
        //public List <SelectOption> fields {get;set;}
    }
    
    
    public void newFilter(){
        System.debug('*******newFilter()');
        filtersWrap fw = new filtersWrap();
        //fw.fields = objectFieldsGetter();
        
        System.debug('fw: '+fw);
        System.debug('ftsWrap: '+ftsWrap);
        ftsWrap.add(fw);
        
        
        System.debug('ftsWrap: '+ftsWrap);
    }
    
    public void testValues(){
        System.debug('*******testValues()');
        System.debug('ftsWrap: '+ftsWrap);
    }
    
}

User-added image
Best Answer chosen by Artem Kalus 7
Pradeep SinghPradeep Singh
Hi, you need to change your code a little bit. Please refer below code
public with sharing class Test_Ctr {
    
    
    public List <filtersWrap> ftsWrap {get;set;}
    public List <SelectOption> listOptions {get;set;}
    
    
    public Test_Ctr(){        
        ftsWrap = new List <filtersWrap> ();
        newFilter();        
        System.debug('ftsWrap: '+ftsWrap);
    }
    
    
    public List<SelectOption> objectFieldsGetter() 
    {
        String selectedObject = 'Task';
        
        Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
        Schema.SObjectType ObjectSchema = schemaMap.get(selectedObject);
        Map<String, Schema.SObjectField> fieldMap = ObjectSchema.getDescribe().fields.getMap();
        List<SelectOption> fieldNames = new List<SelectOption>();
        for (String fieldName: fieldMap.keySet()) 
        {  
            fieldNames.add(new SelectOption(fieldName,fieldName));
        }
        system.debug('============'+fieldNames);
            
        return fieldNames;
    }
    
    
    public class filtersWrap{
        public string fieldvar {get;set;}
        public List <SelectOption> fields {get;set;}
    }
    
    
    public void newFilter(){
        system.debug('-------11111------');
        filtersWrap fw = new filtersWrap();
        fw.fields = objectFieldsGetter();
        ftsWrap.add(fw);
        system.debug('-=-=-=-=-=' + fw);
        
    }
    
    public void testValues(){
        System.debug('---test------');
    }
    
}

 

All Answers

GhanshyamChoudhariGhanshyamChoudhari
<apex:form id="theForm">
        <apex:outputPanel id="thepanel">
        <apex:pageBlock title="Filters">
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton action="{!newFilter}" value="New Filter" rerender="theForm"/>
                <apex:commandButton action="{!testValues}" value="Test Values" rerender="theForm"/>
            </apex:pageBlockButtons>
            
            <apex:pageBlockTable value="{!ftsWrap}" var="row">
                <apex:column> 
                    <!--apex:selectList value="{!row.fieldvar}" size="1">
                        <apex:selectOptions value="{!listOptions}"/>
                    </apex:selectList-->
                    <apex:selectList value="{!row.fieldvar}" size="1" >
                        <apex:actionSupport event="onchange" reRender="thepanel"/>
                        <apex:selectOptions value="{!listOptions}"></apex:selectOptions>
                    </apex:selectList>
                </apex:column>
            </apex:pageBlockTable>             
        </apex:pageBlock>
        </apex:outputPanel>
    </apex:form>

 
Pradeep SinghPradeep Singh
Hi, you need to change your code a little bit. Please refer below code
public with sharing class Test_Ctr {
    
    
    public List <filtersWrap> ftsWrap {get;set;}
    public List <SelectOption> listOptions {get;set;}
    
    
    public Test_Ctr(){        
        ftsWrap = new List <filtersWrap> ();
        newFilter();        
        System.debug('ftsWrap: '+ftsWrap);
    }
    
    
    public List<SelectOption> objectFieldsGetter() 
    {
        String selectedObject = 'Task';
        
        Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
        Schema.SObjectType ObjectSchema = schemaMap.get(selectedObject);
        Map<String, Schema.SObjectField> fieldMap = ObjectSchema.getDescribe().fields.getMap();
        List<SelectOption> fieldNames = new List<SelectOption>();
        for (String fieldName: fieldMap.keySet()) 
        {  
            fieldNames.add(new SelectOption(fieldName,fieldName));
        }
        system.debug('============'+fieldNames);
            
        return fieldNames;
    }
    
    
    public class filtersWrap{
        public string fieldvar {get;set;}
        public List <SelectOption> fields {get;set;}
    }
    
    
    public void newFilter(){
        system.debug('-------11111------');
        filtersWrap fw = new filtersWrap();
        fw.fields = objectFieldsGetter();
        ftsWrap.add(fw);
        system.debug('-=-=-=-=-=' + fw);
        
    }
    
    public void testValues(){
        System.debug('---test------');
    }
    
}

 
This was selected as the best answer
Narender Singh(Nads)Narender Singh(Nads)
Hey Artem, 
The reason your functions are not getting called is because at runtime you are trying to convert a string to selectoption type.
I might be able to point you in the right direction if you can tell what exactly you are trying to achieve.
 
Artem Kalus 7Artem Kalus 7
Pradeep's code works for me. I guess "public SelectOption fieldvar {get;set;}​" was my problem. Should have been "public string fieldvar {get;set;}". Thank you everybody, I appreciate your help. 
 
public class filtersWrap{
        public string fieldvar {get;set;}
        public List <SelectOption> fields {get;set;}
    }