bean-validation

How to match cross-field bean validation errors to a single h:message?

我是研究僧i 提交于 2019-12-06 23:01:37
We're currently building a web application based on JSF and PrimeFaces and want to use Bean Validation to validate the domain model. The problem we currently face is that we want most error messages displayed next to a single input field. For example, suppose there's a constraint "enddate > startdate", implemented as a class-level bean validator, we still want constraint violations for that rule to show up in a h:message/p:message specific to the enddate field rather than in the globalOnly section. Can this be achieved? If so, how? 来源: https://stackoverflow.com/questions/20740685/how-to-match

How to Enable Spring Validation

独自空忆成欢 提交于 2019-12-06 16:25:44
After putting hibernate-validator.jar and javax.validation-api.jar in my classpath the my old validation turned off and org.springframework.dao.DataIntegrityViolationException is replaced by org.hibernate.exception.ConstraintViolationException which wraps SQL exception that is coming from table constraints and this is causing a lot of issues. It automatically turned JSR-303 validation on so it doesn't validate anything anymore. I have to put this two jars to be able to upgrade Jersey to 2.4, it has dependency on these two jars. Putting these properties into hibernate.properties file doesn't

@NotNull Bean Validation ignored for viewParam

可紊 提交于 2019-12-06 16:22:21
Problem I'm trying to validate a mandatory GET request parameter. In the view I've added a corresponding viewParam tag. <f:metadata> <f:viewParam name="customerId" value="#{customerDetailBean.customerId}"/> </f:metadata> And my CDI bean looks like this @Model public class CustomerDetailBean { @NotNull private Integer customerId; public Integer getCustomerId() { return customerId; } public void setCustomerId(Integer customerId) { this.customerId = customerId; } } When I use the following request, validation works fine and the expected validation message is displayed. http://localhost:8080

EJB injection fails in custom ConstraintValidator on JPA persist

被刻印的时光 ゝ 提交于 2019-12-06 11:57:53
I have a problem with my JSF/JPA/Bean Validation app. Custom constraints annotating (JPA) entity fields don’t function correctly on JPA pre-persist although they work fine during JSF form validation Environment: NetBeans IDE 8.0.2 / GlassFish Server 4.1 JPA 2.1/EJB 3.2 /CDI 1.1/BeanValidation 1.1 /Hibernate Validator 5.0.0.Final cdi-api.jar added to ejb/web projects as it seems it was missing. Problem My App contains a JSF 2.2 page whose backing/CDI bean (Register) contains references to fields of (JPA) entities on the server/EJB tier. The entities are annotated with constraint annotations,

Conflict between ValidationMessages.properties files

天大地大妈咪最大 提交于 2019-12-06 11:56:33
问题 I use to collect all my validation constraints in a common library. In the root of the jar I put a ValidationMessages_it.properties file. All works fine, if I put this library into a jsf 2 war project all validation messages are shown correctly. However a problem arise if I put another ValidationMessages_it.properties in the war artifact too. In this case a {library.message_key} string is shown. I think Bean Validation find the right property file in the war and does not take into account

Submit form without bean validation

删除回忆录丶 提交于 2019-12-06 10:51:59
I've got a form which has a domain model with some JSR-303 validation beans. Now I would like to include a "Save draft" feature without any validation. If I set immediate=true on my corresponding commandButton validation is skipped but also the form submit. Is there a way to update the model in my save draft action? BalusC Use <f:validateBean> where on you set the disabled attribute. <h:inputText value="#{bean.input}"> <f:validateBean disabled="#{bean.draft}" /> </h:inputText> If this evaluates true , this will skip all bean validation on the property associated with the input's value. You

How to Validate different model class into one form using Spring MVC JSR-303 Validator

筅森魡賤 提交于 2019-12-06 09:43:32
问题 I have form inside jsp page as below: <springForm:form action="${addAction}" name="frm" method="post" commandName="employee"> <table> <tr> <td><label>First Name</label> </td> <td><springForm:input path="firstName" /></td> <td><springForm:errors path="firstName" cssClass="error" /></td> </tr> <tr> <td><label>Last Name</label></td> <td><springForm:input path="lastName" /></td> <td><springForm:errors path="lastName" cssClass="error" /></td> </tr> <tr> <td><label>Email</label> </td> <td>

Spring Data JPA validation is missing on update (merge)

江枫思渺然 提交于 2019-12-06 09:19:01
I'm working on project with Spring boot 1.5.4.RELEASE with Spring Data JPA. Stuck on issue that Hibernate validator isn't executed when updating entity or at least in some cases it doesn't validate. For Person like below it is forbidden to have empty name and skills collection have to has min 1 element and max 5. Both of them are verified during call save on Spring Data repository. However for call save on already existing entity it will verify only constraints of name - and won't check skills. @Entity public class Person { @Id @GeneratedValue private Long id; @NotBlank private String name;

JSR-303 how to ignore validation on specific fields in a bean some of the time

白昼怎懂夜的黑 提交于 2019-12-06 08:55:42
问题 I am validating a large bean. It is based of a dynamic form page. Some fields that are being validated are not visible on the form and hence empty or null. But I don't want the invisible fields to be validated. Sometimes they are visible and I want them to be validated, sometimes they are not visible and I don't want them to be validated. I first took the approach of stripping these fields from the serialized form before submitting. But it still validates the missing fields because they exist

Doing JSR-303 validation in logical order

橙三吉。 提交于 2019-12-06 08:09:37
I have such field in my domain model class validation constraints: @Column(nullable = false, name = "name") @NotEmpty(groups = {Envelope.Insert.class, Envelope.Update.class}) @Size(min = 3, max = 32) private String name; When this field is empty ("") or null, validator produces both "cannot be empty" and "size must be between..." error messages. I understand it, but when I show this validation error to the client, it seems quite odd (because when something is null / empty it cannot fulfill size requirement, it's not a logical). Is there some way how to tell Spring to do validation in proper