Uploaded image for project: 'MyFaces Core'
  1. MyFaces Core
  2. MYFACES-3299

Programmatically generated components do not register with Bean Validation

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Won't Fix
    • None
    • None
    • None
    • None

    Description

      I am having problems using MyFaces with Bean Validation.

      I am not clear what the JSF spec means, but it says "Consider a simple web application that has one page, written in Facelets for JSF 2, that has a several text fields inside of a form. This application is running in a JSF runtime in an environment that does require JSR 303 Bean Validation, and therefore this feature is available. Assume that every text field is bound to a managed bean property that has at least one Bean Validation constraint annotation attached to it. During the render response phase that always precedes a postback, due to the specification requirements in Section 3.5.3 "Validation Registration", every UIInput in this application has an instance of Validator with id javax.faces.Bean attached to it".

      George Gastaldi and I have created a sample application (attached) that demonstrates several ways of creating a simple input text bound to Bean Validation. This must be deployed to a Java EE 6 container (we tested against JBoss AS 6). You will note the first two pages (Normal Facelets form, Binding Component) work fine. When you click 'Click Me' to POSTback, Bean Validation is invoked and a validation error is displayed.

      The second two pages (Dynamic Component, Dynamic Component (with Metawidget)) do not work as expected. They both use PreRenderViewEvent to create the inputText programmatically. The spec is unclear whether we're meant to explicitly add a javax.faces.Bean validator in this case? The way I read section 3.5.3, I don't think we do, but it doesn't work without it?

      Attachments

        1. jsf-validation.zip
          10 kB
          Kennard Consulting

        Activity

          lu4242 Leonardo Uribe added a comment -

          Closing it as won't fix, because there is nothing we can do in this case. It could create inconsistencies later.

          Anyway, a global listener attached to PostAddToViewEvent could do the job, but it is better if we don't include that in the core implementation.

          lu4242 Leonardo Uribe added a comment - Closing it as won't fix, because there is nothing we can do in this case. It could create inconsistencies later. Anyway, a global listener attached to PostAddToViewEvent could do the job, but it is better if we don't include that in the core implementation.

          Okay it looks like MyFaces determines 'if a JSF 303 engine is present' by doing...

          Class.forName( "javax.validation.Validation" )

          ...in javax.faces.validator._ExternalSpecifications

          kennardconsulting Kennard Consulting added a comment - Okay it looks like MyFaces determines 'if a JSF 303 engine is present' by doing... Class.forName( "javax.validation.Validation" ) ...in javax.faces.validator._ExternalSpecifications

          Okay, that makes sense. Thanks for your clarification.

          Can you please elaborate on 'check the conditions'? I believe JSF adds Bean Validation implicitly to components 'if a JSR 303 engine is present'. But how is that determined? Is there a JSF API? Or does MyFaces look for a specific JSR 303 class?

          kennardconsulting Kennard Consulting added a comment - Okay, that makes sense. Thanks for your clarification. Can you please elaborate on 'check the conditions'? I believe JSF adds Bean Validation implicitly to components 'if a JSR 303 engine is present'. But how is that determined? Is there a JSF API? Or does MyFaces look for a specific JSR 303 class?
          lu4242 Leonardo Uribe added a comment -

          It is expected that no bean validation be bound to programatically added components. It is responsibility (at least theorically) of the developer to check the conditions and add bean validation in this case. I don't see how to solve it in other way.

          lu4242 Leonardo Uribe added a comment - It is expected that no bean validation be bound to programatically added components. It is responsibility (at least theorically) of the developer to check the conditions and add bean validation in this case. I don't see how to solve it in other way.

          Sample application demonstrating different ways to create inputTexts bound to Bean Validation. The two ways that use application.createComponent do not work as expected.

          kennardconsulting Kennard Consulting added a comment - Sample application demonstrating different ways to create inputTexts bound to Bean Validation. The two ways that use application.createComponent do not work as expected.

          People

            lu4242 Leonardo Uribe
            kennardconsulting Kennard Consulting
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: