3

I was trying to add a dropdown menu inside VF page (where I already have other pageBlockTables).
I only need to retrieve one field (c.sfprn) from an existing SOQL query where it is already used for other pageBlockTables.

Here is part of my VF page where I am trying to add a dropdown menu:

    <!-- DropDown Menu starts -->
         <apex:pageBlockTable value="{!RowList}" var="c">
            <apex:column >
                <apex:facet name="header">All Surveys</apex:facet>
                <span>All Surveys: </span>
            <apex:selectList id="AllSurvey" size="1">
            <apex:selectOptions value="http://www.test.com?sfprn={!c.sfprn}&id=1>Test1</apex:selectOptions>
            <apex:selectOptions value="http://www.test.com?sfprn={!c.sfprn}&id=2>Test1</apex:selectOptions>
            </apex:selectList> 
            </apex:column>
         </apex:pageBlockTable>
         <!-- DropDown Menu ends --> 

Here is portion of Apex code:

public PageReference searchPatients(){

    RowList = new List<TableRow2>();
    TableRow2 tr;

    for(Patient__c con : [SELECT sfprn__c, 
                                mrn__c,
                                LName__c, 
                                FName__c,
                                (select SurveySelection__c.SurveySelection__c from SurveySelections__r) 
                                FROM Patient__c
                                where mrn__c =:mrn 
                                or LName__c =:lname LIMIT 1                                
                                ]){

        tr = new TableRow2();
        tr.sfprn = con.sfprn__c;
        tr.mrn = con.mrn__c;
        tr.lname = con.LName__c;
        tr.fname = con.FName__c;
        tr.SurveySelection = con.SurveySelections__r.isEmpty() ? null : con.SurveySelections__r[0].SurveySelection__c;

        RowList.add(tr);
        }
     return null;   
}   

I am curious whether I need to add a new method or I could just call the value="{!RowList}" to bring one field (c.sfprn). Thanks in advance.

2
  • You're missing a closing " for them
    – EricSSH
    May 22, 2017 at 22:31
  • Opps. I added (along with bottom correction), but still getting the same error.
    – Java
    May 22, 2017 at 22:55

1 Answer 1

4

apex:selectOptions is for adding a list of SelectOption objects from Apex. If you want to define the options in visualforce, use apex:selectOption:

<apex:pageBlockTable value="{!RowList}" var="c">
    <apex:column >
        <apex:facet name="header">All Surveys</apex:facet>
        <span>All Surveys: </span>
        <apex:selectList id="AllSurvey" size="1">
            <apex:selectOption itemValue="http://www.test.com?sfprn={!c.sfprn}&id=1" itemLabel="Test1"></apex:selectOption>
            <apex:selectOption itemValue="http://www.test.com?sfprn={!c.sfprn}&id=2" itemLabel="Test1"></apex:selectOption> 
        </apex:selectList>
    </apex:column>
</apex:pageBlockTable>
5
  • I changed to <apex:selectOption> , but still getting "Invalid selectOptions found. Use SelectOption type in Apex." error.
    – Java
    May 22, 2017 at 22:54
  • @KingJava value may not actually be supported, try itemValue. I've updated my answer. May 22, 2017 at 23:30
  • Hi IllusiveBrian. Thanks. The drop down is working, but it does not go to URL.
    – Java
    May 23, 2017 at 14:31
  • @KingJava If you need it to go to the URL, you would need to use javascript or apex:actionSupport. If you need help with that, you should post another question. May 23, 2017 at 15:01
  • I posted it. salesforce.stackexchange.com/questions/175675/… Thanks!
    – Java
    May 23, 2017 at 16:33

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