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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:02:02+00:00 2026-06-13T05:02:02+00:00

public class Register { @NotNull private String password; @NotNull private String passwordRepeat; @AssertTrue private

  • 0
public class Register {
    @NotNull private String password;
    @NotNull private String passwordRepeat;
    @AssertTrue private boolean comparePasswords() { 
       return password.equals(passwordRepeat);
    }

    private Set<ConstraintViolation<Register>> violations;

    public void doRegister(AjaxBehaviorEvent event) {
        Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
        violations = validator.validate(this);

        if(violations.isEmpty()) {
            // This occurs
        }
    }
}

My validation will pass if both my passwords are not null, but they are different.
Seems like the last constraint will not be taken into account, though I do not have a clue why. Does anyone have suggestion?

And no, I am not searching for any implementations of @Matches or simular custom validators. I just would like to get this problem solved.

Thanks in advance.

Update 1

I have run some tests regarding this, hopefully the results will provide needed information.

Bean.java

@Named
@RequestScoped
public class Bean {
    @NotNull private String example1;
    @NotNull private String example2;
    @AssertTrue private boolean examplesMatch() { return example1.equals(example2); }

    private Set<ConstraintViolation<Bean>> violations;
    private FacesContext context;
    private Validator validator;

    @PostConstruct
    public void init() {
        context = FacesContext.getCurrentInstance();
        validator = Validation.buildDefaultValidatorFactory().getValidator();

        example1 = "abc";
        example2 = "def";
        runValidation(false, 1);

        example1 = "abc";
        example2 = "abc";
        runValidation(true, 2);

        example1 = "abc";
        example2 = null;
        runValidation(false, 3);
    }

    private void runValidation(boolean assertion, int testNr) {
        FacesMessage message;
        violations = validator.validate(this);
        if(violations.isEmpty() == assertion) {
            message = new FacesMessage("Passed test nr. " + testNr);
        }
        else {
            message = new FacesMessage("Failed test nr. " + testNr);
        }
        context.addMessage(FacesMessage.FACES_MESSAGES, message);
    }

index.xhtml

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html">
    <head>
        <title>TODO supply a title</title>
    </head>
    <body>
        #{bean}
        <h:messages />
    </body>
</html>

Result

beanvalidation.Bean@31c5c3da

    Failed test nr. 1
    Passed test nr. 2
    Passed test nr. 3 
  • 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-13T05:02:03+00:00Added an answer on June 13, 2026 at 5:02 am

    examplesMatch() is not a valid Java Beans boolean property getter. It needs to start with get or is.

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

Sidebar

Related Questions

I have a viewmodel. public class RegistrationViewModel { public RegisterModel Register { get; set;
public class MyClass { public string MyProperty{ get; set; } Now, I would like
public class A { private A(int param1, String param2) {} public static A createFromCursor(Cursor
class Register { private: DWORD ax,dx,cx,bx; // POH DWORD bp,sp; DWORD flag, ip; public:
I am trying to register the following class using the fluent interface: public class
public class Test { public static void main(String[] args) { DemoAbstractClass abstractClass = new
public class User { public long Id {get;set;} [References(typeof(City))] public long CityId {get;set;} [????]
public class Start { public Register theReg = new Register(); public static Start go
public class AthleteManager { private static Icon anIcon = new ImageIcon(); private static int
I created a custom membership provider public class MyMembership : MembershipProvider { private IRepository<User>

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.