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

Custom component with children: Child component added dynamically at end appears as first child when rendered

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Not A Problem
    • 1.2.6, 1.2.7
    • None
    • None
    • None
    • Windows XP Pro, Tomcat 6.20, Facelets x.14/x.15

    Description

      Child components added dynamically at end appears as first child when rendered. Here is a highly simplified case of the problem (source included):

      The custom component 'repeat' will simply iterate through its children and renders them.

      Usage:

      <netx:repeat binding="#

      {testBean.htmlRepeat}

      ">
      <h:outputText value="Child-1"/>
      <h:outputText value="Child-2"/>
      </netx:repeat>

      Below is how the component renders:

      [begin - Child-1Child-2 - end]

      BackingBean:

      The repeat component is bounded to a backing bean like so:

      public class TestBean {

      private HtmlRepeat htmlRepeat;

      public HtmlRepeat getHtmlRepeat()

      { return null; }

      public void setHtmlRepeat(HtmlRepeat htmlRepeat)

      { this.htmlRepeat = htmlRepeat; }

      // – action method
      public String formSubmitted()

      { System.out.println("formSubmitted()"); Application application = FacesContext.getCurrentInstance().getApplication(); // Create a new child and add it to the parent HtmlOutputText child = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE); child.setValue("Child-3"); htmlRepeat.getChildren().add(child); return null; }

      }

      and the form is submitted using <h:commandButton value="Submit" action="#

      {testBean.formSubmitted}

      "/>

      The formSubmitted() method simply adds a child to htmlRepeat using htmlRepeat.getChildren().add(child). Note that the child is added as the last
      child to the children list. But when the response is rendered, the newly added child appears at the beginning.

      Expected Output:
      [begin - Child-1Child-2Child-3 - end]

      Actual Output:
      [begin - Child-3Child-1Child-2 - end]

      Attachments:

      1. jsf-repeat.jar - Deployable JSF component packaged as jar (contains .java
      files, faces-config.xml and facelet taglib).

      Download >> http://keerthi.linux.googlepages.com/jsf-repeat.jar

      2. TestRepeat.xhtml - Facelet view using the <netx:repeat/> custom component

      Download >> http://keerthi.linux.googlepages.com/TestRepeat.xhtml (Use Save
      target as, otherwise you will get only a blank page)

      Note: Tested on myfaces1.2.6/Tomcat 6.20/Facelets .14 & .15

      Attachments

        Activity

          People

            lu4242 Leonardo Uribe
            kpkeerthi Keerthi
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: