0

I have a table, where each Wrapper instance corresponds to each row of the table. On select of Project - tasks of selected project should be rendered. If i'm trying to pick task and add a new row VF throws an Error. I`ve seen that this error may occur if you passing Set to the VF instead of List. But it's not my case.

VF page:

 <apex:dataTable value="{!wrapperList}" var="w" id="table" border="1 solid black" style="border-collapse: collapse; width:50% ;text-align: center">
        <apex:column headerValue="Project" id="project" rendered="{!IF(w.Project == null, true, false)}" >

            <apex:selectList value="{!w.selectedProjectId}" label="Project" size="1" multiselect="false">

                <apex:selectOptions value="{!w.Projects}"/>
                <apex:actionSupport action="{!w.populateMap}" event="onchange" reRender="task"/>

            </apex:selectList>

        </apex:column>
        <apex:column headerValue="Task" id="task"  rendered="{!IF(w.Task == null, true, false)}">

            <apex:selectList value="{!w.selectedTaskId}" label="Task" required="false" size="1" multiselect="false">

                <apex:selectOptions value="{!w.project2TaskList[w.selectedProjectId]}"/>

            </apex:selectList>

        </apex:column>

Apex Controller:

    public Map<Id, List<SelectOption>> project2TaskList {get; set;}
    public Id selectedProjectId {get; set;}
    public Id selectedTaskId {get; set;}

    public List<SelectOption> getProjects(){

        List<SelectOption> projectOptions = new List<SelectOption>{new SelectOption('', '--Select--')};

        for(Project__c proj: [SELECT Name FROM Project__c WHERE Primary_Contact__c = :selectedContactId]){
            projectOptions.add(new SelectOption(proj.Id, proj.Name));
        }

        return projectOptions;
    }

    public void populateMap(){
        project2TaskList = new Map<Id, List<System.SelectOption>>();

        List<SelectOption> taskOptions = new List<SelectOption>{new SelectOption('', '--Select--')};

        for(Task__c task :taskList){

            if (task.Project__c == selectedProjectId){
                taskOptions.add(new SelectOption(task.Id, task.Name));
            }
        }
        project2TaskList.put(selectedProjectId, taskOptions);
    }

enter image description here

0

It happens when you submit the form and select option values not matches with the list available in the apex.

Can you just not wrap your Add row button in apex:region?

You might want to see the following link same question too. j_id0:frm:pageBlock:artist: Validation Error: Value is not valid

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.