MyFaces Core
  1. MyFaces Core
  2. MYFACES-3610

Dynamically created ClientBehaviors do not call addComponentResource

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.1.7
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      I'm creating this as a JIRA issue so that I can attach a test case. However it behaves the same on Mojarra as on MyFaces so possibly it is 'by design'?

      My question is this:

      • If I dynamically create UIComponents using Application.createComponent, I find they automatically add any dependent resources (JS/CSS) to the h:head. This is fantastic.
      • If I dynamically create ClientBehaviours using Application.createBehavior, no dependent resources get added.

      Am I supposed to add such resources manually? For example:

      UIOutput js = new UIOutput();
      js.setRendererType("javax.faces.resource.Script");
      js.getAttributes().put("library", "mylibrary");
      js.getAttributes().put("name", "bar.js");

      FacesContext context = FacesContext.getCurrentInstance();
      context.getViewRoot().addComponentResource(context, js, "head");

      If so, how am I supposed to know what they are? For example, if I am dynamically adding an AjaxBehavior the exact name of the JavaScript file depends on which JSF implementation I am using.

      1. DynamicBehaviourTest.zip
        3.73 MB
        Kennard Consulting

        Activity

        Hide
        Kennard Consulting added a comment -

        Wonderful. Okay I've updated http://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-1162

        On a personal note: you really are a legend. I can't tell you the number of times I've had a JSF problem, and you have responded promptly and accurately to get it resolved. Thank you!

        Show
        Kennard Consulting added a comment - Wonderful. Okay I've updated http://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-1162 On a personal note: you really are a legend. I can't tell you the number of times I've had a JSF problem, and you have responded promptly and accurately to get it resolved. Thank you!
        Hide
        Leonardo Uribe added a comment - - edited

        Hi Richard

        Yes, any change in that part must be done at spec level, because once the spec is out, we can't do any changes without break binary compatibility.

        The code in place in Application.createBehavior() works just like the one in createComponent(), so if the @ResourceDependency annotation is there, it should work.

        regards,

        Leonardo

        Show
        Leonardo Uribe added a comment - - edited Hi Richard Yes, any change in that part must be done at spec level, because once the spec is out, we can't do any changes without break binary compatibility. The code in place in Application.createBehavior() works just like the one in createComponent(), so if the @ResourceDependency annotation is there, it should work. regards, Leonardo
        Hide
        Kennard Consulting added a comment -

        Leonardo,

        Thank you so much for your response!

        To confirm: you're saying that, in general, Application.createBehavior should dynamically add resources, and that it would work for other ClientBehaviours. But simply that javax.faces.component.behavior.AjaxBehavior has a bug?

        In that case, I should just chase the spec team?

        Regards,

        Richard.

        Show
        Kennard Consulting added a comment - Leonardo, Thank you so much for your response! To confirm: you're saying that, in general, Application.createBehavior should dynamically add resources, and that it would work for other ClientBehaviours. But simply that javax.faces.component.behavior.AjaxBehavior has a bug? In that case, I should just chase the spec team? Regards, Richard.
        Hide
        Leonardo Uribe added a comment -

        I checked the test case and the reason it does not work is because AjaxBehavior does not have @ResourceDependency attached. By the spec we cannot change that so the best way to make it work is create a custom class like this:

        @ResourceDependency(library="javax.faces",name="jsf.js")
        public class DynAjaxBehavior extends AjaxBehavior
        {
        ...

        Show
        Leonardo Uribe added a comment - I checked the test case and the reason it does not work is because AjaxBehavior does not have @ResourceDependency attached. By the spec we cannot change that so the best way to make it work is create a custom class like this: @ResourceDependency(library="javax.faces",name="jsf.js") public class DynAjaxBehavior extends AjaxBehavior { ...
        Hide
        Kennard Consulting added a comment -

        Test case that creates an AjaxBehavior dynamically. No dependent resources get added.

        Show
        Kennard Consulting added a comment - Test case that creates an AjaxBehavior dynamically. No dependent resources get added.

          People

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

            Dates

            • Created:
              Updated:

              Development