MyFaces Tomahawk
  1. MyFaces Tomahawk
  2. TOMAHAWK-1022

HtmlMessage and HtmlMessages fails unit test when using RI

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.1.6, 1.1.7-SNAPSHOT
    • Fix Version/s: 1.1.7
    • Component/s: Message(s)
    • Labels:
      None

      Description

      Below are output from the test failures. The test are run using the following command:

      cd tomahawk/core
      mvn test -Djsf=ri

      -------------------------------------------------------------------------------
      Test set: org.apache.myfaces.component.html.ext.HtmlMessagesTest
      -------------------------------------------------------------------------------
      Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.094 sec <<< FAILURE!
      testDefaultRenderer(org.apache.myfaces.component.html.ext.HtmlMessagesTest) Time elapsed: 0.032 sec <<< ERROR!
      java.lang.IllegalStateException: Parent was not null, but this component not related
      at javax.faces.component.UIComponentBase.eraseParent(UIComponentBase.java:457)
      at javax.faces.component.UIComponentBase.access$500(UIComponentBase.java:76)
      at javax.faces.component.UIComponentBase$ChildrenList.add(UIComponentBase.java:1496)
      at org.apache.myfaces.component.html.ext.HtmlMessagesTest.testDefaultRenderer(HtmlMessagesTest.java:66)

      -------------------------------------------------------------------------------
      Test set: org.apache.myfaces.component.html.ext.HtmlMessageTest
      -------------------------------------------------------------------------------
      Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.031 sec <<< FAILURE!
      testDefaultRenderer(org.apache.myfaces.component.html.ext.HtmlMessageTest) Time elapsed: 0 sec <<< ERROR!
      java.lang.IllegalStateException: Parent was not null, but this component not related
      at javax.faces.component.UIComponentBase.eraseParent(UIComponentBase.java:457)
      at javax.faces.component.UIComponentBase.access$500(UIComponentBase.java:76)
      at javax.faces.component.UIComponentBase$ChildrenList.add(UIComponentBase.java:1496)
      at org.apache.myfaces.component.html.ext.HtmlMessageTest.testDefaultRenderer(HtmlMessageTest.java:66)

        Activity

        Hide
        Paul Spencer added a comment -

        Set affected Versions

        Show
        Paul Spencer added a comment - Set affected Versions
        Hide
        Leonardo Uribe added a comment -

        Checking this behavior, I have noted that this is caused by a difference in the way that jsf ri implements UIComponentBase.getChildren and myfaces.

        The idea when you add a child component to some other component is that child.getParent return the component where it was added. The line:

        referencedComponent.setParent(panelGroup);

        this is the context:

        UIComponent referencedComponent = new HtmlInputText();
        referencedComponent.setId("referencedComponent");
        referencedComponent.setParent(panelGroup);
        panelGroup.getChildren().add(referencedComponent);
        facesContext.addMessage(referencedComponent.getId(), new FacesMessage(
        FacesMessage.SEVERITY_ERROR, "summary", "detail"));

        set the parent to the base component first and then add it. But checking the implementation on myfaces, when the component is added it is also set the parent property, so this code is useless. If exists on the children list, it is removed first and added later.

        I think based on the message of jsf ri:

        java.lang.IllegalStateException: Parent was not null, but this component not related

        when is added, the parent try to check if is on the children list (Note that this do not exists in reality, because there is no add yet). The result on jsf ri is an IllegalStateException, because it try to remove a child component that in fact does not exists.

        The solution is simple: just remove or comment the line:

        referencedComponent.setParent(panelGroup);

        on both test.

        If no objections I'll commit this change.

        Show
        Leonardo Uribe added a comment - Checking this behavior, I have noted that this is caused by a difference in the way that jsf ri implements UIComponentBase.getChildren and myfaces. The idea when you add a child component to some other component is that child.getParent return the component where it was added. The line: referencedComponent.setParent(panelGroup); this is the context: UIComponent referencedComponent = new HtmlInputText(); referencedComponent.setId("referencedComponent"); referencedComponent.setParent(panelGroup); panelGroup.getChildren().add(referencedComponent); facesContext.addMessage(referencedComponent.getId(), new FacesMessage( FacesMessage.SEVERITY_ERROR, "summary", "detail")); set the parent to the base component first and then add it. But checking the implementation on myfaces, when the component is added it is also set the parent property, so this code is useless. If exists on the children list, it is removed first and added later. I think based on the message of jsf ri: java.lang.IllegalStateException: Parent was not null, but this component not related when is added, the parent try to check if is on the children list (Note that this do not exists in reality, because there is no add yet). The result on jsf ri is an IllegalStateException, because it try to remove a child component that in fact does not exists. The solution is simple: just remove or comment the line: referencedComponent.setParent(panelGroup); on both test. If no objections I'll commit this change.
        Hide
        Paul Spencer added a comment -

        I have no objections on removing setParent().

        Show
        Paul Spencer added a comment - I have no objections on removing setParent().

          People

          • Assignee:
            Leonardo Uribe
            Reporter:
            Paul Spencer
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development