bean-validation

Add value into request object before validation

浪尽此生 提交于 2019-12-11 04:14:57
问题 I'm using @Restcontroller and @Vaid annotation. @RequestMapping(path = "/1050" method = RequestMethod.POST, headers = {"Content-Type=application/json"}, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE ) public UserListResp getUserList(@RequestBody @Valid UserListReq request, BindingResult bindingResult, Principal principal){ UserListResp response = new UserListResp(); if (bindingResult.hasErrors()){ response.setResultCode(102); // Validation

Field validation from options on condition from other field javax.validation

£可爱£侵袭症+ 提交于 2019-12-11 04:07:33
问题 I need to perform a field validation (it can be one of values) if another field is present. import javax.validation.*; class Person { @NotBlank private String name; private Long groupId; @Valid // if group id is not null, select one from available. private String specialization; // getters, setters. } class PersonValidaionLogic { @Autowired private SpecializationService specializationService; public void validatePerson(final Person person) { Long groupId = person.getGroupId(); if (groupId !=

@Valid not throwing exception

↘锁芯ラ 提交于 2019-12-11 03:54:51
问题 I'm trying to validate my JPA Entity with @Valid like this: public static void persist(@Valid Object o) It worked fine for a while but now it stopped working and I'm not sure why. I tried to do it manually inside the persist method, and it works as expected: ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); Validator validator = factory.getValidator(); Set<ConstraintViolation<Object>> constraintViolations = validator.validate(o); if (!constraintViolations.isEmpty()) {

JSF2 BeanValidation reset values after failure

喜夏-厌秋 提交于 2019-12-11 03:12:43
问题 The modules of our web application shows a datatable in the center and the detail of the selected record on the right. Every time the user selects a record of the mastertable we update the detail page and show the details of the selected record. Now we have the following problem: User selects a record in the mastertable and data is displayed in detail area. User modifies the detail data and clicks on save. An validation(bean validation) error occurs and the user will see the error msg).

Disable not null checks in Kotlin

谁说胖子不能爱 提交于 2019-12-11 02:33:32
问题 class User(val name: String) I know that in constructor will be added this check Intrinsics.checkParameterIsNotNull(name) To make sure that name do not store null. Is there a way to instrument to not generate such checks? Maybe an annotation? We need this in Spring, when map json string to a class. The validation is done by @NotNull and @Valid from javax class User(@field:NotNull @field:Email val name: String) so, checks are performed immediately after object creation, but since exceptions

Spring bean validation messages resolution

[亡魂溺海] 提交于 2019-12-11 02:33:19
问题 I want to do a very specific task, get all validation messages for every field in an Object . First task is easy, getting all Annotations for field in Object , also recursively, was already done. (modified code from html5val dialect for thymeleaf) private List<Annotation> fieldAnnotations() { Field field = this.fieldFinder.findField(this.targetClass, this.targetFieldName); if (field != null) { List<Annotation> annotations = Arrays.asList(field.getAnnotations()); List<Annotation> toAdd = new

Temoporarily suppress beanvalidation with JSF

六眼飞鱼酱① 提交于 2019-12-11 00:23:17
问题 i have a User class with a field for the e-mail-address and a password. @NotNull @Size(min=6) @Pattern(flags=Pattern.Flag.CASE_INSENSITIVE ,regexp="[^ ]*") private String password = null; @NotNull) @Size(max=60) @EmailUse // Check if the email-address is already in the database @Email private String emailAddress = null; This code works well at the registration. But when the user will edit his data i have a Problem with the Password and with the @EmailUse tag. The password is at the <h

How to remove redundant Spring MVC method by providing POST-only @Valid?

安稳与你 提交于 2019-12-10 23:54:24
问题 I have a form-handling Spring MVC controller with JSR-303 bean validation by @Valid . The only purpose of whole GET -handler is to act (almost) the same as POST , but omitting @Valid annotation to prevent displaying of errors in JSP <form:errors ...> on the first user GET request before he submits the form. My question is: How can I remove the redundant GET method in a clean way? How can I make a POST -only @Valid ? Here is my example code: @RequestMapping( value = "/account/register" ,

Omnifaces validateBean: attach message to specific component

浪尽此生 提交于 2019-12-10 22:34:49
问题 I am using Omnifaces <o:validateBean /> to use JSR303 bean validation with a class level constraint. The whole thing works quite good. The validation message is displayed in a Primefaces <p:messages /> component. Now I wanted to know whether it is possible to narrow the error message to a more precise component (i. e. a <p:message /> tag on a specific element)? In the example below I want to direct the error message to the <p:message /> component with id="id_msg_anniversary" (or if that is

How can I have validation errors printed on failure

做~自己de王妃 提交于 2019-12-10 20:40:16
问题 given the following dto and controller public class PasswordCredentials implements AuthenticationProvider { @NotNull @NotEmpty @JsonProperty( access = JsonProperty.Access.WRITE_ONLY ) private String user; @NotNull @NotEmpty @JsonProperty( access = JsonProperty.Access.WRITE_ONLY ) private CharSequence pass; public void setPass( final CharSequence pass ) { this.pass = pass; } public void setUser( final String user ) { this.user = user; } @Override public Authentication toAuthentication() {