bean-validation

JSF/Hibernate NotBlank validation

随声附和 提交于 2019-12-02 09:37:56
I have a simple JSF+RichFaces form with some fields and obviously a backing bean to store them. In that bean all the necessary properties have validation annotations (jsr303/hibernate), but I can't seem to find an annotation which would check if the property (String) is blank. I know there's a @NotBlank annotation in spring modules, but JSF doesn't support spring validation. Is there any easy way to check it or should I write my own annotation? @Edit: I already tried @NotNull and @NotEmpty from jsr303 and hibernate, but they both failed I still can send a blank string like " ". If you use

Conditional Bean Validation

二次信任 提交于 2019-12-02 08:02:37
I am using Bean Validation in my JSF project. Now I have come across a situation in which I would like to validate a method ONLY when a preceding method is validated. I will give an example: @AssertTrue(message="{invalidCode}") private boolean isValidActivationCode() { ... } if(isValidActivationCode()) { @AssertTrue(message="{alreadyActivated}") private boolean isAlreadyActivated() { ... } } Since I will receive the Activation Code per parameter, I would like to validate it first. If it is not valid, it will cause a violation. If so, I cannot even check whether it is already activated (since

javax.validation.ValidationException: Unable to find a default provider

核能气质少年 提交于 2019-12-02 06:34:15
问题 I added some validation ( @NotNull ) to managed beans and suddenly got this error. Any ideas what might cause it? The application runs in Apache Tomcat 7. javax.validation.ValidationException: Unable to find a default provider javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:264) javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:111) javax.faces.validator.BeanValidator.validate(BeanValidator.java:271) javax.faces.component.UIInput.validateValue

How to inject spring bean into Validator(hibernate)

ⅰ亾dé卋堺 提交于 2019-12-02 04:05:45
spring doc I have read the following spring documentation: By default, the LocalValidatorFactoryBean configures a SpringConstraintValidatorFactory that uses Spring to create ConstraintValidator instances. This allows your custom ConstraintValidators to benefit from dependency injection like any other Spring bean. I have wrote custom validator: public class FieldMatchValidator implements ConstraintValidator<FieldMatch, Object>{ @Autowired MyBeanDao dao; ... } But in debug I see that dao is null. Please, explain I didn't understand documentation or I wrong configured something? Use Spring

javax.validation.ValidationException: Unable to find a default provider

假装没事ソ 提交于 2019-12-02 01:45:13
I added some validation ( @NotNull ) to managed beans and suddenly got this error. Any ideas what might cause it? The application runs in Apache Tomcat 7. javax.validation.ValidationException: Unable to find a default provider javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:264) javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:111) javax.faces.validator.BeanValidator.validate(BeanValidator.java:271) javax.faces.component.UIInput.validateValue(UIInput.java:1127) javax.faces.component.UIInput.validate(UIInput.java:941) javax.faces.component

How to autowire service in ConstraintValidator

社会主义新天地 提交于 2019-12-01 20:56:28
I'm writting my application using Spring MVC. I want to validate is e-mail exists in database when user is registering. I've written my own annotation constraint named UniqueEmail . My User entity User.java : @Entity @Table(name="users") public class User { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Integer id; @Column(name = "email", length = 100, nullable = false, unique = true) @NotEmpty @Email @UniqueEmail(message = "E-mail is not unique") private String email; @Column(name = "password", nullable = false) @NotEmpty @Size(min = 5, message = "size must be more 5") private

Hibernate JSR303 validation and incorrectly generated propertyPath

不羁岁月 提交于 2019-12-01 20:45:21
I'm trying to set up JSR-303 validation of forms using Spring MVC. I had everything configured correctly (or at least I think I do), and validations are working mostly correctly. However, if I have a command object that contains a Collection of objects that I want validated, and I annotate that Collection with @Valid, the Hibernate JSR-303 provider is not providing the correct propertyPath. The propertyPath inside the ContraintViolation object should be populated like list[0].bar and list[1].bar , but the Hibernate validator is simply providing list[].bar and list[].bar . This causes a

How can I skip bean validation if all fields for the entity are empty?

断了今生、忘了曾经 提交于 2019-12-01 19:46:15
问题 I have a address entity like this: @Entity public class Address implements java.io.Serializable { @Id @GeneratedValue(strategy = IDENTITY) private Long id; @Size(max = 100) private String street; @Size(max = 15) private String nr; @Field @Size(min = 1, max = 20) @NotBlank private String city; } This is part of several other entities. For one such entity the address is optional. I have a view where our users can edit the whole entity via several form inputs, including several address fields.

hibernate validator - different groups on create, update, delete

℡╲_俬逩灬. 提交于 2019-12-01 19:44:56
Using bean validation, particular hibernate validator implementation is it possible to define certain groups to automatically be used on certain crud operations like create or update? or are there some build in hibernate groups that are internally checked for those operations? You're probably looking for "Hibernate event-based validation" under "ORM Integration" . You can set properties to specify which groups to validate at different times by setting properties on the SessionFactory like so: <property name="javax.persistence.validation.group.pre-persist">javax.validation.Default</property>

Bean validation not working if name variable is prefixed with underscore

自闭症网瘾萝莉.ら 提交于 2019-12-01 19:18:12
I'm trying out some bean validation and I'm stumbling upon 'strange' behavior. I'm working with Glassfish and Primefaces as a front-end (if it makes any difference). Elsewhere in my project I use the Hibernate-validator, I'm not sure if it is validating JSF (else it is the default in Glassfish). I have a managed bean: @javax.faces.bean.ManagedBean @javax.faces.bean.ViewScoped public class TestBean { @Size(min=8) private String _testString; public String getTestString() { return _testString; } public String setTestString(String testString) { _testString = testString; } public void doSomethind()