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 6738965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:25:52+00:00 2026-05-26T11:25:52+00:00

In my JSF application I have two <h:inputText> components. I need to make sure

  • 0

In my JSF application I have two <h:inputText> components. I need to make sure that value is entered in at least one of them. How can I implement such a validator?

I am aware that I can use JavaScript for this, but I’d prefer to do the checks in the server side.

  • 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-26T11:25:53+00:00Added an answer on May 26, 2026 at 11:25 am

    Bind the components to the view, create a <h:inputHidden value="true"> which you put before the components wherein you attach the validator and pass the components as attributes.

    E.g.

    <h:inputHidden value="true" requiredMessage="Please fill in at least one of those fields">
        <f:validator validatorId="oneOrMoreValidator" />
        <f:attribute name="component1" value="#{component1}" />
        <f:attribute name="component2" value="#{component2}" />
    </h:inputHidden>
    
    <h:inputText binding="#{component1}" ... />
    <h:inputText binding="#{component2}" ... />
    

    with this @FacesValidator("oneOrMoreValidator") implementation:

    @Override
    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
        List<UIInput> inputs = new ArrayList<UIInput>();
        boolean hasValue = false;
    
        for (int i = 1; i < Integer.MAX_VALUE; i++) {
            UIInput input = (UIInput) component.getAttributes().get("component" + i);
    
            if (input != null) {
                inputs.add(input);
    
                if (!hasValue) {
                    Object submittedValue = input.getSubmittedValue();
                    hasValue |= (submittedValue != null && !String.valueOf(submittedValue).isEmpty());
                }
            } else {
                break;
            }
        }
    
        if (!inputs.isEmpty() && !hasValue) {
            for (UIInput input : inputs) {
                input.setValid(false);
            }
    
            String requiredMessage = (String) component.getAttributes().get("requiredMessage");
            throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, requiredMessage, null));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have follow following code in my JSF application <t:dataList id=slider-one value=#{MyBean.banners} var=ofr layout=simple
I have a JSF application that uses mostly Richfaces. I would like to introduce
I have a JSF application with several major components and a component tree under
I have a legacy JSF application. Now that we want to add i18n support
We have JSF web application that generates XLS file and gives user link to
I have been trying with limited success to code a JSF application. In one
I have a JSF application that makes much use of session-scoped variables. A new
I am running JSF 2.0 I currently have one java controller that is called
I have a JSF/ICEFaces application that was working fine but all of the sudden
I am developing a web application using JSF and JPA(Eclipse link). I have two

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.