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

  • SEARCH
  • Home
  • 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 8883649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:51:58+00:00 2026-06-14T20:51:58+00:00

I am using JSF 2.0. I have a h:selectOneMenu on my page which contains

  • 0

I am using JSF 2.0.

I have a h:selectOneMenu on my page which contains a list of values and there is one h:inputText on the same page, whose required should depend on the currently selected value of the h:selectOneMenu. Only a certain set of values should trigger the required check, others not.

This is what I have tried:

<h:inputText ... required="#{(selectedPaymentType.value == 'some value') || (selectedPaymentType.value == 'other value')}" />

In the code above #{selectedPaymentType} is definied in h:selectOneMenu binding.

There are 3 more values like this which should trigger the required attribute to true. This looks kind of clumsy. Are there better ways to do so?

  • 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-06-14T20:52:00+00:00Added an answer on June 14, 2026 at 8:52 pm

    Fant has given a hint in the right direction, that you should be using an enum which has a required property, but it seems that you’re not entirely sure how to properly implement it. Admittedly, Fant’s answer is not elaborate enough. So here’s a more elaborate answer.

    Basically, you need to replace all dropdown values by an enum which look like this:

    public enum PaymentType {
        FOO("Some label for foo", true),
        BAR("Some label for bar", false),
        BAZ("Some label for baz", true);
    
        private String label;
        private boolean required;
    
        private PaymentType(String label, boolean required) {
            this.label = label; 
            this.required = required;
        }
    
        public String getLabel() { 
            return label;
        }
    
        public boolean isRequired() {
            return required;
        }
    }
    

    And use it as follows

    <h:selectOneMenu binding="#{selectedPaymentType}" value="#{bean.selectedPaymentType}">
        <f:selectItems value="#{bean.availablePaymentTypes}" var="paymentType"
            itemValue="#{paymentType}" itemLabel="#{paymentType.label}" />
    </h:selectOneMenu>
    <h:inputText ... required="#{selectedPaymentType.value.required}" />
    

    with

    private PaymentType selectedPaymentType; // +getter+setter
    
    public PaymentType[] getAvailablePaymentTypes() { 
        return PaymentType.values();
    }
    

    (or if you’re using OmniFaces, use <o:importConstants>, then you don’t need such a getter for the <f:selectItems>; no, you don’t need a converter in any case, JSF/EL has already builtin conversion for enums)

    See, the required attribute is now so much more simplified as it’s already definied in the model associated with the selected value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some JSF-trouble using h:selectOneMenu with a list from my backend bean: My
(Using jsf-2) I have a dataTable with one column which can be edited: <h:column>
I have a standard JSF h:form which contains an h:SelectOneMenu control. As long as
I'm using JSF 2.0. I have a managed bean which I can access through
I am using Struts Tiles with JSF to have one header, menu and footer
I'm using JSF 2.0 and want to fill a selectOneMenu with the values of
I have an application using PrettyFaces and PrimeFaces. One page is accessed using the
Hi i have created a custom converter in jsf for combo box using h:selectOneMenu,
I am using JSF 1.1. I have a JSF page with a request scoped
I have completed an application using JSF 1.x, which is up and running. The

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.