[Issue 358] New - Custom component with children - Child component added dynamically at end appears as first child when rendered <full source code included>

View: New views
1 Messages — Rating Filter:   Alert me  

[Issue 358] New - Custom component with children - Child component added dynamically at end appears as first child when rendered <full source code included>

by kpkeerthi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

https://facelets.dev.java.net/issues/show_bug.cgi?id=358
                 Issue #|358
                 Summary|Custom component with children - Child component added
                        |  dynamically at end appears as first child when rende
                        |red <full source code included>
               Component|facelets
                 Version|ALL
                Platform|All
              OS/Version|All
                     URL|
                  Status|NEW
       Status whiteboard|
                Keywords|
              Resolution|
              Issue type|DEFECT
                Priority|P1
            Subcomponent|jsf
             Assigned to|issues@facelets
             Reported by|kpkeerthi






------- Additional comments from kpkeerthi@... Thu Oct 29 07:26:00 +0000 2009 -------
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:

<custom:repeat binding="#{testBean.htmlRepeat}">
        <h:outputText value="Child-1"/>
        <h:outputText value="Child-2"/>
</custom: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

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@...
For additional commands, e-mail: issues-help@...