Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 898689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:05:17+00:00 2026-05-15T15:05:17+00:00

I am working on a JSF page which has a dropdown based on List<SelectItem>

  • 0

I am working on a JSF page which has a dropdown based on List<SelectItem>:

<h:selectOneMenu value="#{bean.selectedItem}">
    <f:selectItems value="#{bean.availableItems}" />
</h:selectOneMenu>

I need to get both the value and label of the currently selected item. Right now I only get the value. How can I get the label, too?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T15:05:17+00:00Added an answer on May 15, 2026 at 3:05 pm

    You can’t. That’s just how HTML works. You know, JSF is a HTML code generator. The JSF <h:selectOneMenu> generates a HTML <select><option> . The HTML <select> element will only send the value attribute of the selected <option> element. It will not send its label.

    But that shouldn’t be a big issue. You namely already know both the value and label in the server side, inside the #{bean.availableItems}. All you need to do to get the associated label is to get it by the value as key. I suggest to make it a Map which in turn can also be used in f:selectItems.

    Basic kickoff example:

    public class Bean {
        private String selectedItem; // +getter +setter
        private Map<String, String> availableItems; // +getter
    
        public Bean() {
            availableItems = new LinkedHashMap<String, String>();
            availableItems.put("value1", "label1");
            availableItems.put("value2", "label2");
            availableItems.put("value3", "label3");
        }
    
        public void submit() {
            String selectedLabel = availableItems.get(selectedItem);
            // ...
        }
    }
    

    with

    <h:selectOneMenu value="#{bean.selectedItem}">
        <f:selectItems value="#{bean.availableItems.entrySet()}" var="entry"
            itemValue="#{entry.key}" itemLabel="#{entry.value}" />
    </h:selectOneMenu>
    

    and in result

    <p>Selected label is #{bean.availableItems[bean.selectedItem]}</p>
    

    An alternative is to wrap both name and value in a javabean object representing an entity and set the whole object as value, via a converter.

    See also:

    • Our selectOneMenu wiki page
    • How to populate options of h:selectOneMenu from database?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on JSF page which displays settings values and updates settings into Oracle
I have a JSF/Seam web app which has a page with a form which,
I'm working on a JSF project, and it has a login.xhtml file, which a
I'm working on this JSF table which is used for displaying data. When I
I'm working on a Java EE (which I'm fairly new to) web application (JSF,
I have the following line in a JSF page: <h:commandLink action=#{myBean.test} value=Wizard Step></h:commandLink> I
So I have bean named element that has a list of categories in and
I have a JSF project and I already have an index.xhtml page which is
I'm mostly working with legacy code in a JSF based project and there are
I want to create simple select menu which changes <div> layers in JSF page.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.