bean-validation

spring mvc process object before @valid is applied

拟墨画扇 提交于 2020-01-04 02:54:56
问题 I have a spring mvc controller like the following @RequestMapping(value="/new", method=RequestMethod.POST) public String createBooking(@Valid Booking booking, BindingResult bindingResult, Model model, Principal principal) { if(bindingResult.hasErrors()) { return "booking/edit"; } //Store Booking in db... ... The problem is the Booking object i get from the POST is constructed by Spring, but one of the properties required by the validator cannot be populated, as the property is not present in

Bean Validation Fails on Hibernate Proxy? Expected Behavior?

随声附和 提交于 2020-01-03 13:35:14
问题 Im using hibernate-core-4.0.1.Final hibernate-validator-4.2.0.Final I have a lazy loadable Entity @NotNull @OneToOne(fetch = FetchType.LAZY,optional = false,cascade = CascadeType.PERSIST) @JoinColumn(name="library_id") private Library library; public Library getLibray() { return library; } and a defaultValidator private final ValidatorFactory factory = Validation .buildDefaultValidatorFactory(); private final Validator val = factory.getValidator(); When I am trying to validate unattached and

Bean Validation Fails on Hibernate Proxy? Expected Behavior?

可紊 提交于 2020-01-03 13:34:16
问题 Im using hibernate-core-4.0.1.Final hibernate-validator-4.2.0.Final I have a lazy loadable Entity @NotNull @OneToOne(fetch = FetchType.LAZY,optional = false,cascade = CascadeType.PERSIST) @JoinColumn(name="library_id") private Library library; public Library getLibray() { return library; } and a defaultValidator private final ValidatorFactory factory = Validation .buildDefaultValidatorFactory(); private final Validator val = factory.getValidator(); When I am trying to validate unattached and

Empty input value does not triggger @NotNull but it triggers @NotBlank

▼魔方 西西 提交于 2020-01-02 10:31:18
问题 i have this entity: import javax.validation.constraints.NotNull; import org.hibernate.validator.constraints.NotBlank; @Entity @XmlRootElement @Table public class Supplier extends AbstractEntity { @Column @NotNull private String name; @Column @NotBlank private String representative; ... } and this jsf form: <h:form> <p:commandButton value="save" action="#{supplierController.create}" ajax="false"/> <h:panelGrid columns="3" cellpadding="4"> <h:outputLabel value="#{bundle['Name']}" for="name"/>

Bean Validation on method

人走茶凉 提交于 2020-01-02 09:56:26
问题 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

Database access from jsr-303 custom validator

╄→尐↘猪︶ㄣ 提交于 2020-01-02 07:11:22
问题 I'm using spring based validation in combination with hibernate validator enabled by the following in my application context: <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> .... <property name="jpaPropertyMap"> <map> <entry key="javax.persistence.validation.factory" value-ref="validator" /> </map> </property> </bean> <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/> I've

Database access from jsr-303 custom validator

你说的曾经没有我的故事 提交于 2020-01-02 07:11:20
问题 I'm using spring based validation in combination with hibernate validator enabled by the following in my application context: <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> .... <property name="jpaPropertyMap"> <map> <entry key="javax.persistence.validation.factory" value-ref="validator" /> </map> </property> </bean> <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/> I've

If I use two custom annotations in jsr 303 how to stop validation for second annotation if validation failed on first?

我是研究僧i 提交于 2020-01-02 03:30:15
问题 I have the next issue while working with jsr303: i have field annotated the next way: @NotEmpty(message = "Please specify your post code") @PostCode(message = "Your post code is incorrect") private String postCode; But I need to check @PostCode only if field passed the validation for @NotEmpty. How can I checking for tese two annotations? Thanks in advance 回答1: You can use validation groups to execute validations group-wise. For details, see section 3.4. Group and group sequence in JSR-303.

bean validation not working with kotlin (JSR 380)

℡╲_俬逩灬. 提交于 2020-01-02 00:13:28
问题 so first of all i could not think of a better title for this question so i'm open for changes. I am trying to validate a bean using the bean validation mechanism (JSR-380) with spring boot. So i got a controller like this: @Controller @RequestMapping("/users") class UserController { @PostMapping fun createUser(@Validated user: User, bindingResult: BindingResult): ModelAndView { return ModelAndView("someview", "user", user) } } with this being the User class written in kotlin: data class User(

How to make @PreAuthorize having higher precedence than @Valid or @Validated

不想你离开。 提交于 2020-01-01 08:35:12
问题 I am using spring boot, and I have enabled the global method security in WebSecurityConfigurerAdapter by @EnableGlobalMethodSecurity(prePostEnabled = true, order = Ordered.HIGHEST_PRECEDENCE) And Below is my controller code @PreAuthorize("hasAnyRole('admin') or principal.id == id") @RequestMapping(value = "/{id}", method = RequestMethod.PUT) public User updateUser(@PathVariable("id") String id, @Valid @RequestBody UserDto userDto) { ....} However, when a non-admin user try to do a PUT request