bean-validation

How to perform JSF validation in actionListener or action method?

与世无争的帅哥 提交于 2019-11-26 11:51:34
I have Bean validation working nicely in my application. Now I want to check that a new user does not choose a username that has already been chosen. In the actionlistener I have the code that checks the database but how do I force the user to be sent back to the page they were on if they choose an already existing username? BalusC Introduction You can do it, but JSF ajax/action/listener methods are semantically the wrong place to do validation. You actually don't want to get that far in JSF lifecycle if you've wrong input values in the form. You want the JSF lifecycle to stop after JSF

Unique constraint with JPA and Bean Validation

拈花ヽ惹草 提交于 2019-11-26 10:56:45
问题 I\'d like to have a @Unique constraint with Bean Validation, but that is not provided by the standard. If I would use JPA\'s @UniqueConstraint I wouldn\'t have a unique validation and error reporting mechanism. Is there a way to define @Unique as a Bean Validation constraint and combine it with JPA, such that JPA creates a column with an unique constraint and checks wheter a value is unique or not? 回答1: Unless you acquire a lock on a whole table , it is basically not possible to check for

Is there an implementation of JSR-303 (bean validation) available?

倾然丶 夕夏残阳落幕 提交于 2019-11-26 09:35:24
问题 I know there are non-standard frameworks such as commons-validator, and hibernate validator. I wanted to know if someone knows an implementation of the official standard. 回答1: Hibernate Validator is the reference implementation of JSR-303 回答2: There are 2 compliant implementations now: Apache Bean Validation (formerly agimatec) Hibernate Validator You can access a benchmark and a quick description of both here: http://carinae.net/2010/06/benchmarking-hibernate-validator-and-apache

Annotations from javax.validation.constraints not working

余生颓废 提交于 2019-11-26 09:25:39
问题 What configuration is needed to use annotations from javax.validation.constraints like @Size , @NotNull , etc.? Here\'s my code: import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; public class Person { @NotNull private String id; @Size(max = 3) private String name; private int age; public Person(String id, String name, int age) { this.id = id; this.name = name; this.age = age; } } When I try to use it in another class, validation doesn\'t work (i.e. the

Hibernate Validation of Collections of Primitives

≡放荡痞女 提交于 2019-11-26 04:10:55
问题 I want to be able to do something like: @Email public List<String> getEmailAddresses() { return this.emailAddresses; } In other words, I want each item in the list to be validated as an email address. Of course, it is not acceptable to annotate a collection like this. Is there a way to do this? 回答1: Neither JSR-303 nor Hibernate Validator has any ready-made constraint that can validate each elements of Collection. One possible solution to address this issue is to create a custom

Bean Validation @NotNull, @NotBlank and @NotEmpty does not work in JSF+Tomcat

空扰寡人 提交于 2019-11-26 03:56:26
问题 I am using Hibernate Validation annotations in my JSF managed bean. When I use @NotNull , @NotBlank or @NotEmpty they doesn\'t seem to be triggered in any way. @NotBlank(message = \"{name.required}\") public String name; View: <h:outputLabel value=\"Name:\" /> <h:inputText id=\"name\" value=\"#{person.name}\" size=\"20\" /> <h:message for=\"name\" style=\"color:red\" /> How is this caused and how can I solve it? 回答1: Introduction Since you didn't give any feedback on my comment with the

How can I validate two or more fields in combination?

邮差的信 提交于 2019-11-26 02:49:53
问题 I\'m using JPA 2.0/Hibernate validation to validate my models. I now have a situation where the combination of two fields has to be validated: public class MyModel { public Integer getValue1() { //... } public String getValue2() { //... } } The model is invalid if both getValue1() and getValue2() are null and valid otherwise. How can I perform this kind of validation with JPA 2.0/Hibernate? With a simple @NotNull annotation both getters must be non-null to pass validation. 回答1: For multiple

How to perform JSF validation in actionListener or action method?

我的未来我决定 提交于 2019-11-26 02:37:38
问题 I have Bean validation working nicely in my application. Now I want to check that a new user does not choose a username that has already been chosen. In the actionlistener I have the code that checks the database but how do I force the user to be sent back to the page they were on if they choose an already existing username? 回答1: Introduction You can do it, but JSF ajax/action/listener methods are semantically the wrong place to do validation. You actually don't want to get that far in JSF

Cross field validation with Hibernate Validator (JSR 303)

心已入冬 提交于 2019-11-25 22:05:47
问题 Is there an implementation of (or third-party implementation for) cross field validation in Hibernate Validator 4.x? If not, what is the cleanest way to implement a cross field validator? As an example, how can you use the API to validate two bean properties are equal (such as validating a password field matches the password verify field). In annotations, I\'d expect something like: public class MyBean { @Size(min=6, max=50) private String pass; @Equals(property=\"pass\") private String