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
glorgeglorge 

BUG: Error referencing SelectOption object in Visualforce Function

I am getting an error when trying to reference a SelectObject component inside of a Visualforce function.  The following code sample, which attempts to set the default value in a dropdown based on an input parameter, demonstrates the issue.  

 

Visualforce Page:

 

 

<apex:page controller="Bug">

<form action="{!$Page.bug}">

<select name="selected">

<apex:repeat value="{!selectOptions}" var="o">

<option value="{!o.value}" {!IF(o.value = selected, 'selected', '')}>

{!o.label}

</option>

</apex:repeat>

</select>

<input type="submit" value="Go!"/>

</form></apex:page>

 

 

Controller Class:

 

public class Bug {

public List<SelectOption> selectOptions {get; set;}

public String selected {get; set;}

public Bug()

{

selectOptions = new List<SelectOption>();

selectOptions.add(new SelectOption('S1', 'Select One'));

selectOptions.add(new SelectOption('S2', 'Select Two'));

selectOptions.add(new SelectOption('S3', 'Select Three'));

selected = ApexPages.currentPage().getParameters().get('selected');

}

}

 

 

 I get the following error when I try to compile the Visualforce page:

 

Save error: Incorrect parameter for function =(). Expected Object, received Text

 

For whatever reason,  the compiler seems to be think SelectObject.getValue() returns an Object rather than a String.  

 

Interestingly enough, when I swap out the controller with the following functionally identical controller, the Visualforce page compiles without issue:

 

 

public class Bug {

public List<CustomSelectOption> selectOptions {get; set;}

public String selected {get; set;}

 

public class CustomSelectOption

{

public String value {get; set;}

public String label {get; set;}

public CustomSelectOption(String value, String label)

{

this.value = value;

this.label = label;

}

}

 

public Bug()

{

selectOptions = new List<CustomSelectOption>();

selectOptions.add(new CustomSelectOption('S1', 'Select One'));

selectOptions.add(new CustomSelectOption('S2', 'Select Two'));

selectOptions.add(new CustomSelectOption('S3', 'Select Three'));

 

selected = ApexPages.currentPage().getParameters().get('selected');

}

}

 

 

 

Any ideas here?  Obviously there is a simple workaround here - but it seems to me that the original code should have compiled just fine.  

 

Thanks,

Greg 

Message Edited by glorge on 03-08-2010 03:05 PM
Message Edited by glorge on 03-08-2010 03:06 PM
stephanstephan
I was able to replicate your issue and it does seem like a bug. Thanks for bringing this to our attention. Stay tuned for more...
Rajesh ShahRajesh Shah

<option value="{!o.value}" {!IF(o.value = selected, 'selected', '')}>

 

Maybe its because the if needs to be part of the rendered attribute or maybe its just a typo in the thread. Just wanted it to bring it to attention.
glorgeglorge

Hi Rajesh,

 

Thanks for the suggestion.  However, given that the same Visualforce page compiles without error when I swap in the second controller, I don't think that this is caused by a syntax error in the Visualforce page.  

 

Thanks,

Greg

Rajesh ShahRajesh Shah
That is weird. What would the if condition mean if it is not assigned to a attribute?
acl5acl5

I am having the same issue, but with a picklist field.  I have tried several formulas...ISPICKVAL, TEXT, CASE, and I get :

 

ErrorError: Incorrect parameter for function ISPICKVAL(). Expected Picklist, received Text 

 

 

Here is a sample VF page I mocked up to show my issue:

<apex:page standardController="Account"> <apex:form > <apex:pageBlock id="block1" > <apex:inputField value="{!Account.Name}" rendered="{!IF(ISPICKVAL(Account.Industry,'high'),true,false)}"/> <apex:inputField value="{!Account.CustomerPriority__c}"> <apex:actionSupport event="onchange" reRender="block1"/> </apex:inputField> </apex:pageBlock> </apex:form> </apex:page>

 


 

fb123fb123

I'm also getting the same error for a picklist field on a VF page. Have you found a workaround?

VinnySusanthVinnySusanth

Hi..

 

I am also facing this issue where i have to compare the value of a select option to another value.

Is this bug fixed

 

Thanks,

Vini

stephanstephan

We're working on a fix for this for the Winter '11 release (October 2010).

 

...stephan

VinnySusanthVinnySusanth

Hi,

 

Is there any workaround for this problem.I have a critical development that has to be completed.

 

<apex:repeat var="serv" value="{!ServiceValues}" >
                                   
                       <apex:repeat value="{!SelectedServices}" var="filterService">
                         <apex:image url="{$Resource.ut}" rendered="{!(serv.value == filterService)}"/>    
                       </apex:repeat>
                          
                          <apex:commandLink  action="{!Services_NarrowSearch}" value="{!serv.label}" >
                          <apex:param name="Services" value="{!serv.value}"/>
                          </apex:commandLink><br/><br/> 
                           
 </apex:repeat>  

 

I tried getting the value to an input field(hidden) and then comparing its value.

<apex:inputHidden id="servs" value="{!serv.value}"/> and then comparing servs

==filterService instead of  "{!(serv.value == filterService)}"

Although it compiled,the functionality did not work.

 

Please help me to find a solution to this problem.

 

Thanks in Advance,

Vinny