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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:21:13+00:00 2026-05-22T23:21:13+00:00

JSF 2.0 only allows you to validate the input on one field, like check

  • 0

JSF 2.0 only allows you to validate the input on one field, like check to see if it’s a certain length. It doesn’t allow you to have a form that says, “enter city and state, or enter just a zip code.”

How have you gotten around this? I’m only interested in answers that involve the validation phase of JSF. I’m not interested in putting validation logic in Managed Beans.

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

    The easiest custom approach I’ve seen and used as far is to create a <h:inputHidden> field with a <f:validator> wherein you reference all involved components as <f:attribute>. If you declare it before the to-be-validated components, then you can obtain the submitted values inside the validator by UIInput#getSubmittedValue().

    E.g.

    <h:form>
        <h:inputHidden id="foo" value="true">
            <f:validator validatorId="fooValidator" />
            <f:attribute name="input1" value="#{input1}" />
            <f:attribute name="input2" value="#{input2}" />
            <f:attribute name="input3" value="#{input3}" />
        </h:inputHidden>
        <h:inputText binding="#{input1}" value="#{bean.input1}" />
        <h:inputText binding="#{input2}" value="#{bean.input2}" />
        <h:inputText binding="#{input3}" value="#{bean.input3}" />
        <h:commandButton value="submit" action="#{bean.submit}" />
        <h:message for="foo" />
    </h:form>
    

    (please note the value="true" on the hidden input; the actual value actually doesn’t matter, but keep in mind that the validator won’t necessarily be fired when it’s null or empty, depending on the JSF version and configuration)

    with

    @FacesValidator(value="fooValidator")
    public class FooValidator implements Validator {
    
        @Override
        public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
            UIInput input1 = (UIInput) component.getAttributes().get("input1");
            UIInput input2 = (UIInput) component.getAttributes().get("input2");
            UIInput input3 = (UIInput) component.getAttributes().get("input3");
            // ...
            
            Object value1 = input1.getSubmittedValue();
            Object value2 = input2.getSubmittedValue();
            Object value3 = input3.getSubmittedValue();
            // ...
        }
    
    }
    

    If you declare the <h:inputHidden> after the to-be-validated components, then the values of the involved components are already converted and validated and you should obtain them by UIInput#getValue() or maybe UIInput#getLocalValue() (in case the UIInput isn’t isValid()) instead.

    See also:

    • Validator for multiple fields (JSF 1.2 targeted)

    Alternatively, you can use 3rd party tags/components for that. RichFaces for example has a <rich:graphValidator> tag for this, Seam3 has a <s:validateForm> for this, and OmniFaces has several standard <o:validateXxx> components for this which are all showcased here. OmniFaces uses a component based approach whereby the job is done in UIComponent#processValidators(). It also allows customizing it in such way so that the above can be achieved as below:

    <h:form>
        <o:validateMultiple id="foo" components="input1 input2 input3" validator="#{fooValidator}" />
        <h:inputText id="input1" value="#{bean.input1}" />
        <h:inputText id="input2" value="#{bean.input2}" />
        <h:inputText id="input3" value="#{bean.input3}" />
        <h:commandButton value="submit" action="#{bean.submit}" />
        <h:message for="foo" />
    </h:form>
    

    with

    @ManagedBean
    @RequestScoped
    public class FooValidator implements MultiFieldValidator {
    
        @Override
        public boolean validateValues(FacesContext context, List<UIInput> components, List<Object> values) {
            // ...
        }
    }
    

    The only difference is that it returns a boolean and that the message should be specified as message attribute in <o:validateMultiple>.

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

Sidebar

Related Questions

How to allow a text field to permit only digits in JSF? I searched
Do the JSF selectOne and selectMany controls only allow submission of values defined in
JSF is setting the ID of an input field to search_form:expression . I need
I have a JSF page. At one point, I have a <h:selectManyCheckbox> that is
I have a JSF 1.2 application (Sun RI, Facelets, Richfaces) that was used only
I have a screen with 2 JSF Input Components : inputText and inputText with
I am developing an application in JSF 2.0 and I would like to have
Have JSF 1.2 two pages(one.xhtml and other.xhtml), that are included to the current page
I have the following simple Javascript code that allows only digits to be entered
if there is no data to display, jsf data table shows headers only. How

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.