bean-validation

JSF 2.0, Bean Validation and labels

て烟熏妆下的殇ゞ 提交于 2019-12-12 17:33:10
问题 How can I show the field label in a JSF error message when bean validation is used? <h:messages/> <h:inputText label="Username" value="#{myBean.username}" /> ... public class MyBean { @NotNull private String username; ... } If no user name is submitted only "Must not be null" is shown and there is no field reference. 回答1: To display the concerned component's label in the error message define a new value for the property javax.faces.validator.BeanValidator.MESSAGE in a resource bundle of the

Is there a way to add JSR303-annotations to cxf-generated classes?

╄→尐↘猪︶ㄣ 提交于 2019-12-12 14:30:27
问题 The title probably said it all, I was wondering if one could tell the cxf-codegen-plugin to add, for example, the xsd-patterns as @Pattern annotations. Schema validation is nice and all, but sometimes I just want to check a single element and not endless myriads of xml lines. Therefor I was wondering if there is a trick / option / dirty hack out there that would help me turning <xs:simpleType name="string2000"> <xs:restriction base="xs:string"> <xs:maxLength value="2000"/> <xs:minLength value

How can I disable javax.validation.api in JBoss 6.4

天涯浪子 提交于 2019-12-12 13:34:52
问题 Similar questions: How to use bean validation 1.1 in JBoss EAP 6.4.0? How to change bean-validation version on jboss EAP 6.3? Can you use bean validation 1.1 (JSR 349) in JBoss EAP 6.4.4? There seems to be some uncertainty if we can use Bean Validation 1.1 in JBoss 6.x. My current jboss-deployment-structure.xml: <?xml version="1.0" encoding="UTF-8"?> <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0"> <deployment> <dependencies> <!-- list of modules taken from https:/

Adding javax.validation capabilities to Tomcat

蓝咒 提交于 2019-12-12 12:25:57
问题 I'm trying to run a web application using Tomcat but the the application is using libraries such as: import javax.validation.constraints.Future; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; These libraries are not part of the Tomcat spec so I need to add them manually. What libraries should I add? 回答1: The javax.validation package is a Bean Validation (JSR-303) library. An implementation of this specification is i.e. the Hibernate Validator or the

javax.validation: Receive an error 'No validator could be found for type:'

有些话、适合烂在心里 提交于 2019-12-12 10:58:16
问题 Framework: JQuery, Spring, Hibernate, Hibernate Validator(JSR-303 Bean Validation) Platform: Windows I am trying to define a custom constraint @IdMustExist using JSR 303-Bean Validation. The purpose of the constraint is to check whether the entered id value exists in associated table. I am receiving an error 'javax.validation.UnexpectedTypeException: No validator could be found for type: com.mycompany.myapp.domain.package1.class1'. If I place @IdMustExist on a field definition of Class1 (as

How to create a constraint validator for multiple fields through annotation in spring 4.*

会有一股神秘感。 提交于 2019-12-12 09:54:55
问题 How to create a validator restrictions for more fields through annotation in spring 4.* for example @UniqueValidator @Entity @Table(name = "persons") @UniqueValidator(message="Peson already exist",columns={"name","lastName"}) public class { @Column private String name; @Column private String lastName; } roughly speaking.. select ... from persons where name='qwerty' and lastName='asdfgh' 回答1: Here's one way to do it in Spring MVC and JSR 303 validation: Create a constraint annotation: package

Validate request headers with Spring validation framework

╄→гoц情女王★ 提交于 2019-12-12 09:53:50
问题 Is it possible to use the Spring validation framework with Spring MVC to validate the presence and value of an HTTP request header? 回答1: To check the presence of a request header, you don't need the validation framework. Request header parameters are mandatory by default, and if a mandatory header is missing in a request, Spring MVC automatically responds with 400 Bad Request. So the following code automatically checks the presence of the header "Header-Name"... @PostMapping("/action") public

Purpose of @NotNull.List

情到浓时终转凉″ 提交于 2019-12-12 08:47:33
问题 When I looked among the standard constraints in Bean Validation API (JSR-303), I found the NotNull.List annotation. Its description is: Defines several @NotNull annotations on the same element This is valid syntax: @NotNull.List({@NotNull, @NotNull}) private Object myObject; But it makes no sense. Either the object is null or it is not. When would you use this annotation? There are several other similar annotations like AssertFalse.List and AssertTrue.List . 回答1: You can have multiple

JSF: How validate fields and return error messages by bean validation?

坚强是说给别人听的谎言 提交于 2019-12-12 08:43:25
问题 I have a contact form and I have some fields that are validated by bean validation, how could I return bean validation error messages after submitting? For example: <h:form> <h:inputText id="name" value="#{contact.client.name}"></h:inputText>Name (Required) <h:inputText id="email" value="#{contact.client.email}"></h:inputText>E-Mail (Required) <h:inputText id="website" value="#{contact.client.website}"></h:inputText>Website (Optional) <h:inputText id="text" value="#{contact.client.text}"></h

The orders of bean validation default parameters?

霸气de小男生 提交于 2019-12-12 08:33:14
问题 I am currently trying to provide a custom validation message using bean validation. Currently using spring mvc 3.1.1 + apache bean validation. In my bean, i specify : @Size(min=1, max=50) private String title; And in my messages.properties : Size.addForm.title=The title must not be empty and must not exceed {1} characters. From experiment, i found out that : {0} refers to 'title' {1} refers to the max, which is 50 {2} refers to the min, which is 1 and it'll be displayed as The title must not