I need to get the boolean from a selectList. For example I have the following code.

<apex:selectList id="chooseRule" value="{!}" size="1">
                            <apex:selectOption itemEscaped="false" itemValue="bContains" itemLabel="Contains"/>
                            <apex:selectOption itemEscaped="false" itemValue="bStart" itemLabel="Start with"/>
                            <apex:selectOption itemEscaped="false" itemValue="bNotEqual" itemLabel="Not Equal to"/>

How can I show in my code behind, something like:

If(bContains == true){ do something}

Something like that?. Thanks!

1 Answer 1


You'd want to bind your apex:selectList to a string input:

<apex:selectList id="chooseRule" value="{!selectedChooseRule}" ...

In your Apex Code, you could use getters to define your Boolean values:

public String selectedChooseRule { get; set; }
public Boolean bContainsRule { get { return selectedChooseRule == 'bContains'; } }

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .