bean-validation

How do I get Spring MVC to invoke validation in a JUnit test?

故事扮演 提交于 2019-12-17 18:21:55
问题 I have a POJO called Browser that I've annotated with Hibernate Validator annotations. import org.hibernate.validator.constraints.NotEmpty; public class Browser { @NotEmpty private String userAgent; @NotEmpty private String browserName; ... } I've written the following unit test that tries to verify my Controller method catches validation errors. @Test public void testInvalidData() throws Exception { Browser browser = new Browser("opera", null); MockHttpServletRequest request = new

what to use, managed beans (backing beans) or entity beans?

本小妞迷上赌 提交于 2019-12-17 07:25:32
问题 I see a lot of examples marking beans as entity beans (@Entity) & named beans (CDI), so as to avoid creating 2 classes (managed bean & entity bean) and also to make use of Bean Validation so that validation can be performed on both client & server. So should I be using a single class or not, are there any issues or should I be having my managed beans or service layer create entity beans using the data from managed beans ? 回答1: The @Named or @ManagedBean annotations are typically used to let

JSR 303 Validation, If one field equals “something”, then these other fields should not be null

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-17 02:55:12
问题 I'm looking to do a little custom validation with JSR-303 javax.validation . I have a field. And If a certain value is entered into this field I want to require that a few other fields are not null . I'm trying to figure this out. Not sure exactly what I would call this to help find an explanation. Any help would be appreciated. I am pretty new to this. At the moment I'm thinking a Custom Constraint. But I'm not sure how to test the value of the dependent field from within the annotation.

Hibernate validator constraints in XML

故事扮演 提交于 2019-12-14 04:22:27
问题 I am using xml file to specify my constraints on an incoming request bean. I do this in a validation-constraints.xml file as follows: <?xml version="1.0" encoding="UTF-8"?> <constraint-mappings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/mapping validation-mapping-1.0.xsd" xmlns="http://jboss.org/xml/ns/javax/validation/mapping"> <default-package>com.mathworks.internal.business.geoTypes </default-package> <bean class=

JSR-303 validation is ignored when custom Validator is annotated with @Component

妖精的绣舞 提交于 2019-12-14 00:26:02
问题 I've noticed that JSR-303 validation is completely ignored in Spring when a custom Validator bean annotated with @Component is declared. Interestingly enough said custom validator doesn't even have to filled in or used by any of the classes. The fact that its component scanned by Spring appears to be enough to make Spring skip JSR-303 validation during object binding altogether. Removing @Component from custom Validator and restarting web application enables JSR-303 validation as expected.

Using bean validation (JSR 303) in JSF2 - Primefaces application

坚强是说给别人听的谎言 提交于 2019-12-13 19:22:04
问题 I'm trying to integrate bean validation using hibernate validator to my web application : - Hibernate-spring-jsf2-primefaces3 on tomcat 7 I added following jar files : hibernate-validator.jar and validation-api.jar to my classpath in Netbeans. In the pojo class, I added annotation for Size : @Size(min=4, message="Min 4 chars!") private String name; In the .xhtml page I wrote : <p:inputText title="name" id="name" value="#{myBean.user.name}"></p:inputText> <p:message for="name" /> after running

ArquillianProxyException instead of ConstrainViolationException in JUnit @Test(expected)

百般思念 提交于 2019-12-13 13:13:37
问题 When using Arquillian to test my (JPA) entities as part of an integration test, everything seems seems to work, except testing for ConstraintViolation s. For example it should not be possible to persist an entity instance which had null values in fields annotated with Bean Validation's @NotNull. Instead of a ConstrainViolationException I get ArquillianProxyException : Unexpected exception, expected<javax.validation.ConstraintViolationException> but was<org.jboss.arquillian.test.spi

Restrict Hibernate to not recognize Validation annotations on DDL generation

心已入冬 提交于 2019-12-13 06:44:41
问题 I've been using hbm2ddl=update for Database creations until now. But right now we're going to remove the hbm2ddl property and use SchemaExport tool of Hibernate to create sql statement based on the Hibernate Annotated model classes. SchemaExport is also completed right now. But when I'm making sure that hibernate generated database and SchemeExport generated schema sql are same by using mysqldiff tool on two databases (hibernate generated & SchemaExport generated), there are few columns which

Can you use bean validation 1.1 (JSR 349) in JBoss EAP 6.4.4?

匆匆过客 提交于 2019-12-13 02:39:58
问题 We are using bean validation in JBoss EAP 6.4.4 (resteasy & hibernate-validator 4) to validate REST payload data. As it seems JBoss 6.4.4 uses bean validation 1.0 which doesn't support method validation. So, requests are not being blocked by bean validation and reach the db. Is there any jboss deployment file or something similar where I can enable version 1.1? I cannot change the bundled libs because we'll lose jboss support for the AS. JBoss 7 seems to work out of the box, but it's still in

How to customize default message for BigDecimal

假装没事ソ 提交于 2019-12-12 21:12:47
问题 Here are the models: public class myFormData { private BigDecimal trackingNumber; @Valid private List<myCustomRecord> records = new ArrayList<myCustomRecord>(); } public class myCustomRecord { //the field also appears here (for child records) private BigDecimal trackingNumber; } I have a controller method which receives this object at some point to do a save. public @ResponseBody ValidationResponse save(Model model, @Valid myFormData formData, BindingResult result, HttpSession session){ //do