You need to sign in to do that
Don't have an account?
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
<option value="{!o.value}" {!IF(o.value = selected, 'selected', '')}>
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
I am having the same issue, but with a picklist field. I have tried several formulas...ISPICKVAL, TEXT, CASE, and I get :
Error: 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>
I'm also getting the same error for a picklist field on a VF page. Have you found a workaround?
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
We're working on a fix for this for the Winter '11 release (October 2010).
...stephan
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