0

How could I catch the value {!items} selected and capture it in a variable? I need a simple line of code.

<apex:pageBlock tabStyle="Account" title="Merge Accounts">
          <apex:pageBlockSection title="Choose Accounts to Merge" collapsible="false">
            <apex:selectList label="Account 1" value="{!accounts}" size="1">
                <apex:selectOptions value="{!items}"/>
            </apex:selectList>
              <!--//[Account to merge]-->
            <apex:selectList label="Account 2" value="{!accounts}" size="1">
                <apex:selectOptions value="{!items}"/>
            </apex:selectList>
        </apex:pageBlockSection>
    </apex:pageBlock>

Here is the methods in controller

public String[] accounts = new String[]{};

    public PageReference test() {
        return null;
    }
    //Here the accounts are invoke
    public List<SelectOption> getItems() 
    {
        List<Account> lstAcc = [select id,name from account limit 10];
        List<SelectOption> options = new List<SelectOption>();

        for(Account acc : lstAcc)
        {
            options.add( new SelectOption( acc.id,acc.Name ));
        }
        return options;
    }
    //Here we get the accounts in getiing them
    public String[] getAccounts() {
        return accounts;
    }
    //Here we set the accounts in setting them
    public void setAccounts(String[] accounts) {
        this.accounts = accounts;
    }

I need to catch the value from selectList in a variable to make validations in a new method. Thanks in advance.

1 Answer 1

1

The value attribute of the apex:selectList tag holds a selected value from the list. You should define an apex variable for that:

public string selectedValue { get; set; }

<apex:selectList label="Account 1" value="{!selectedValue}" size="1">

For more info just read the manual: apex:selectList

You must log in to answer this question.

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