Spring + JSF2 + JSR 303 bean validation

prule

I'm using Spring 3.2.2 with Primefaces 4.0 and Hibernate 4.2. I have JSR 303 validation annotations on my entities, and I have spring configured to validate them at the service layer - that much works fine.

But I'd like JSF validation to kick in before calling the service but it doesn't. All the research I've done says I just have to add a validator to the classpath and JSF2 will automatically apply.

I've added the suggested jars to my classpath:

[INFO] |     +- com.sun.faces:jsf-api:jar:2.2.4:compile
[INFO] |     +- com.sun.faces:jsf-impl:jar:2.2.4:compile
[INFO] |     +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] |     +- org.hibernate:hibernate-validator:jar:4.3.1.Final:compile
[INFO] |     +- org.primefaces.extensions:primefaces-extensions:jar:1.0.0:compile
[INFO] |     |  +- org.primefaces:primefaces:jar:4.0:compile
[INFO] |     +- org.slf4j:slf4j-api:jar:1.7.5:compile
[INFO] |     +- org.slf4j:slf4j-log4j12:jar:1.7.5:compile
[INFO] |     |  \- log4j:log4j:jar:1.2.17:compile
[INFO] |     \- org.jboss.logging:jboss-logging:jar:3.1.3.GA:compile

Full dependency tree can be seen at https://gist.github.com/prule/7411171

My validated object and managed bean:

public class ValidatedObject {
    @NotEmpty
    String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

@ManagedBean
@RequestScoped
public class ValidatedController {
    private ValidatedObject object = new ValidatedObject();

    public ValidatedObject getObject() {
        return object;
    }


    public void onSave() {
        System.out.println("saving");
    }
}

Facelets page:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">

<f:view contentType="text/html">

    <h:body>
        <h:form >
            <p:messages />
            <p:outputLabel for="name" value="Name"/>
            <p:inputText id="name" value="#{validatedController.object.name}"/>
            <p:commandButton value="Save" action="#{validatedController.onSave}" ajax="false"/>
        </h:form>
    </h:body>

</f:view>
</html>

Spring config contains:

<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/>
<bean class="org.springframework.validation.beanvalidation.MethodValidationPostProcessor">
    <property name="validator" ref="validator"/>
</bean>

All the questions and answers I've found are basic JSF2 (without spring) or spring-web based. Have I got something missing or incorrect with my spring/jsf integration?

Thanks.

Ioannis Deligiannis

AFAIK, Spring is not compatible (yet) with JEE7/JSF2.2 Bean validation. Either wait for a compatible set or use a JEE7 compatible DI framework like JBoss WELD that is shipped by default with GF4.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Can JSR 303 Bean Validation be used with Spring Data Rest?

From Dev

Spring mvc controller jsr 303 basic list validation

From Dev

How to break coupling between bean and validator with Bean Validation (JSR303)?

From Dev

Spring MVC: use different JSR-303 validators on the same bean?

From Dev

How to implement multiple JSR-303 validation messages for the same @Constraint?

From Dev

JSR 303 bean validation unit testing with Mockito and Autowiring

From Dev

Is EclipseLink MOXy capable of applying JSR-303 Bean Validation when unmarshalling XML to object?

From Dev

Inline validation using JSR-303 in GWT, part 2: A good implementation?

From Dev

Spring JSR-303 bean validation not working, empty bindingresult

From Dev

Nested validation groups, Spring, JSR 303

From Dev

Wildfly: ExceptionMapper not triggered with RestEasy JSR-303 Bean Validation

From Dev

JSR-303 validation groups define a default group

From Dev

kotlin data class + bean validation jsr 303

From Dev

Implementing custom validation logic for a spring boot endpoint using a combination of JSR-303 and Spring's Validator

From Dev

JSR - 349 bean validation for Spring @RestController with Spring Boot

From Dev

Implementing custom validation logic for a spring boot endpoint using a combination of JSR-303 and Spring's Validator

From Dev

Spring Boot JSR-303/349 configuration

From Dev

GWT JSR303 Validation, validate method OR use custom annotations

From Dev

JSR303 validation doesn't validate if @Id is not @GeneratedValue with Spring Data Jpa and Hibernate

From Dev

Spring mvc controller jsr 303 basic list validation

From Dev

Consistent JSR-303 validation with optional properties in Spring controllers and Spring webflow?

From Dev

Spring MVC: use different JSR-303 validators on the same bean?

From Dev

Exception while binidng form to bean using Spring MVC, JSR 303 Annotation

From Dev

Is EclipseLink MOXy capable of applying JSR-303 Bean Validation when unmarshalling XML to object?

From Dev

JSR-303 Bean Validation Collection Values

From Dev

Trouble spring injection in JSF2 Bean with annotation

From Dev

spring boot jsr 303 validation with nested array path fails

From Dev

BindingResult not working in Spring 3.2.8 using JSR-303 BEAN VALIDATION

From Dev

bean validation (JSR 303) for primefaces not working

Related Related

  1. 1

    Can JSR 303 Bean Validation be used with Spring Data Rest?

  2. 2

    Spring mvc controller jsr 303 basic list validation

  3. 3

    How to break coupling between bean and validator with Bean Validation (JSR303)?

  4. 4

    Spring MVC: use different JSR-303 validators on the same bean?

  5. 5

    How to implement multiple JSR-303 validation messages for the same @Constraint?

  6. 6

    JSR 303 bean validation unit testing with Mockito and Autowiring

  7. 7

    Is EclipseLink MOXy capable of applying JSR-303 Bean Validation when unmarshalling XML to object?

  8. 8

    Inline validation using JSR-303 in GWT, part 2: A good implementation?

  9. 9

    Spring JSR-303 bean validation not working, empty bindingresult

  10. 10

    Nested validation groups, Spring, JSR 303

  11. 11

    Wildfly: ExceptionMapper not triggered with RestEasy JSR-303 Bean Validation

  12. 12

    JSR-303 validation groups define a default group

  13. 13

    kotlin data class + bean validation jsr 303

  14. 14

    Implementing custom validation logic for a spring boot endpoint using a combination of JSR-303 and Spring's Validator

  15. 15

    JSR - 349 bean validation for Spring @RestController with Spring Boot

  16. 16

    Implementing custom validation logic for a spring boot endpoint using a combination of JSR-303 and Spring's Validator

  17. 17

    Spring Boot JSR-303/349 configuration

  18. 18

    GWT JSR303 Validation, validate method OR use custom annotations

  19. 19

    JSR303 validation doesn't validate if @Id is not @GeneratedValue with Spring Data Jpa and Hibernate

  20. 20

    Spring mvc controller jsr 303 basic list validation

  21. 21

    Consistent JSR-303 validation with optional properties in Spring controllers and Spring webflow?

  22. 22

    Spring MVC: use different JSR-303 validators on the same bean?

  23. 23

    Exception while binidng form to bean using Spring MVC, JSR 303 Annotation

  24. 24

    Is EclipseLink MOXy capable of applying JSR-303 Bean Validation when unmarshalling XML to object?

  25. 25

    JSR-303 Bean Validation Collection Values

  26. 26

    Trouble spring injection in JSF2 Bean with annotation

  27. 27

    spring boot jsr 303 validation with nested array path fails

  28. 28

    BindingResult not working in Spring 3.2.8 using JSR-303 BEAN VALIDATION

  29. 29

    bean validation (JSR 303) for primefaces not working

HotTag

Archive