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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:16:54+00:00 2026-05-16T23:16:54+00:00

I have two fields representing data range (from and to). I need to check

  • 0

I have two fields representing data range (“from” and “to”). I need to check if either both fields are filled on none of them, so only moment there should be validation message shown is when one is filled and not second one. How can I do that? I thied this custom validator and add it to both fields (as JSF doesn’t validate empty fields) but it always show that they are not valid.

public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
  String otherControlId = (String) component.getAttributes().get("otherControlId");
  UIInput otherControlInput = (UIInput) context.getViewRoot().findComponent(otherControlId);
  Object otherControlValue = otherControlInput.getValue();
  if ((value == null && otherControlValue != null) || (value != null && otherControlValue == null)) {
 //show message
  }
}

otherControlId points to second control ID, and I get a control in validator. But otherControlValue is always null.

  • 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-16T23:16:55+00:00Added an answer on May 16, 2026 at 11:16 pm

    Components are processed in the order as they appear in the component tree. So if the otherControlInput appears after the currently validated component in the component tree, then it’s not processed yet. You would then need to access its (unconverted and unvalidated!) value by UIInput#getSubmittedValue() instead of UIInput#getValue().

    Object otherControlValue = otherControlInput.getSubmittedValue();
    

    An alternative is to put the validator on the other component (the one that appears the last in the tree) instead of the current component, then you can get the value by UIInput#getValue().

    A completely different alternative is to let required attribute depend on each other:

    <h:inputText binding="#{from}" value="#{bean.from}" required="#{not empty to.submittedValue}" />
    <h:inputText binding="#{to}" value="#{bean.to}" required="#{not empty from.value}" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two fields in separate linked tables with the same data, but different
I have two fields that need to multiply each other and fill a third
I have two fields - end and start date(daterange) and I should pass them
I have two fields Price From and Price To + Currency Unit'. I want
I have two fields like this Field1 : Field2 - I have them stored
I have two fields on the form ( forgotpassword form ) username and email
I have two fields on my web page ie: BookAuthor and BookDescription.On submit,the page
I have two fields - amount (decimal (11, 2)) - gift_amount (decimal (11, 2))
I have two fields which calculate a total, but I have a radio button
I have two fields that I'd like to match. (already done the validation functions

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.