How to display default values(first item selected) in SelectOneChoice

Use Case – User wanted to display first item as selected in SelectOneChoice(Dropdown).

Solution – By default ADF displays blank space if nothing is selected in the dropdown.

1. Create one variable in managedBean Private SelectItem defaultChoice;

2. Create Getter/Setter for the variable

3. in getDefaultChoice()

a. Take List which is used to display choices in dropdown

b. return below from getDefaultChoice()

return new SelectItem(list.get(0).toString());

4. set SelectOneChoice value=”#{scope.managedBeanName.defaultChoice.value}”

5. You are done…enjoy!

Advertisements

4 comments

  1. Hi, I tried the same steps as specified in this post because I have the same requirement.But it doesn’t seem to work.
    I populate the values for selectoneChoice in backing bean and have put that in a List. I want to set the first value in list or a particular value as default value of SelectOneChoice on page load.

    I thought this approach will solve my problem, but it didn’t. Could you please suggest me any solution?

      1. Hi Abhishekshahi I fixed the issue. Issue was with the scope of bean.
        Thank you very much for your reply and post.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s