MyFaces Core
  1. MyFaces Core
  2. MYFACES-3299

Programmatically generated components do not register with Bean Validation

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      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?

      1. jsf-validation.zip
        10 kB
        Kennard Consulting

        Activity

        Hide
        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.

        Show
        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.
        Hide
        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.

        Show
        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.
        Hide
        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?

        Show
        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?
        Hide
        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

        Show
        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

          People

          • Assignee:
            Unassigned
            Reporter:
            Kennard Consulting
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:

              Development