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

                 Key: MYFACES-2392
                 URL: https://issues.apache.org/jira/browse/MYFACES-2392
             Project: MyFaces Core
          Issue Type: Bug
    Affects Versions: 1.2.7, 1.2.6
         Environment: Windows XP Pro, Tomcat 6.20, Facelets x.14/x.15
            Reporter: Keerthi


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

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to