2

i am just wondering what is the best way to validate password confirmation in JSF 2

Mahmoud Saleh
  • 33,303
  • 119
  • 337
  • 498

2 Answers2

3

The best way to validate anything you need in JSF is use MyFaces Extval. It support cross field validation, which is a typical use case for validate passwords. See this blog for more information about it.

lu4242
  • 2,318
  • 1
  • 15
  • 15
1

You can use RichFaces 4 client-side! validation based on Bean Validation (JSR303).

Bean:

@Size(min = 5, max = 15)
private String password1;

@Size(min = 5, max = 15)
private String password2;

@AssertTrue(message = "Passwords don't match")
public boolean checkPassword() {
    return password1.equals(password1);
}

Page:

<rich:graphValidator value="#{bean}" id="crossField">
    <h:inputText value="#{bean.password1}"/>
    <h:inputText value="#{bean.password2}"/>
    <rich:message for="crossField"/>
</rich:graphValidator>

Refer here for more examples.

Andrey
  • 6,526
  • 3
  • 39
  • 58
  • but i am using icefaces and some times pure jsf, so how can i do it without richFaces ? – Mahmoud Saleh Sep 24 '11 at 12:20
  • IceFaces and RichFaces work well together, you can add RichFaces to your app also. I see the following options for you: 1) RichFaces 2) seam-faces 3) a workaround, refer here: http://stackoverflow.com/q/6282466/854386. – Andrey Sep 24 '11 at 12:34