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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:31:43+00:00 2026-06-04T14:31:43+00:00

I know I can get the old value through UIInput#getValue() . But in many

  • 0

I know I can get the old value through UIInput#getValue().

But in many cases where the field is bound to a bean value I want to get the default value that I don’t need to validate if the input equals the default value.

This is very usefull if a certain field has a unique constraint and you have a editing form.
Validation will always fail since in a check constraint method it will always find its own value thus validating to false.

One way would be to pass that default value as an attribute using <f:attribute> and check inside the validator. But is there an easier built-in way?

  • 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-04T14:31:45+00:00Added an answer on June 4, 2026 at 2:31 pm

    The submitted value is just available as value argument in the validate() implementation.

    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
        Object oldValue = ((UIInput) component).getValue();
    
        if (value != null ? value.equals(oldValue) : oldValue == null) {
            // Value has not changed.
            return;
        }
    
        // Continue validation here.
    }
    

    An alternative is to design the Validator as a ValueChangeListener. It’ll then only be invoked when the value has really changed. It’s somewhat hacky, but it does the job you really need.

    <h:inputText ... valueChangeListener="#{uniqueValueValidator}" />
    

    or

    <h:inputText ...>
        <f:valueChangeListener binding="#{uniqueValueValidator}" />
    </h:inputText>
    

    with

    @ManagedBean
    public class UniqueValueValidator implements ValueChangeListener {
    
        @Override
        public void processValueChange(ValueChangeEvent event) throws AbortProcessingException {
            FacesContext context = FacesContext.getCurrentInstance();
            UIInput input = (UIInput) event.getComponent();
            Object oldValue = event.getOldValue();
            Object newValue = event.getNewValue();
    
            // Validate newValue here against DB or something.
            // ...
    
            if (invalid) {
                input.setValid(false);
                context.validationFailed();
                context.addMessage(input.getClientId(context),
                    new FacesMessage(FacesMessage.SEVERITY_ERROR, "Please enter unique value", null));
            }
        }
    
    }
    

    Note that you cannot throw a ValidatorException there, that’s why need to manually set both the component and faces context to invalid and manually add the message for the component. The context.validationFailed() will force JSF to skip the update model values and invoke action phases.

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

Sidebar

Related Questions

I know I can get touch events in my iPhone app. But these touch
I know you can get the SQL, but it's paramterized without the parameters being
I know I can get answers here but I was wondering if anyone knows
I know that I can get word completion through CTRL+N & CTRL+P and code
Does anyone know how I can get the value of an input box, without
I know that I can get a POSIX int file handle from NSURL by
Does anyone know how I can get the phone number of the device I
Does anyone know how I can get the helpful Eclipse popups with javadoc when
Does anybody know where I can get a free web crawler that actually works
Does anybody know How I can get the ckEdtior to work with Selenium. I'm

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.