Hi, Yes I was, and it does seem correctly done too... Who's in charge of calling the formSubmitted method? Is is an action on a commandLink/Button?
On Tue, Oct 27, 2009 at 9:56 AM, <kpanneersel...@inautix.co.in> wrote: > > Hi Simon, > Thanks for responding. I'm not quite sure what you mean by getter > code for the navigation bar. Are you asking about the getter/setter for the > navigation bar in my backing bean? > > *public* *class* TestBean { > > *private* HtmlNavigationBar navigationBar; > > *public* HtmlNavigationBar getNavigationBar() { > *return* *null*; > } > > *public* *void* setNavigationBar(HtmlNavigationBar navigationBar) > { > *this*.navigationBar = navigationBar; > } > } > > Thanks. > > > *Simon Lessard <simon.lessar...@gmail.com>* > > 10/27/2009 07:13 PM > Please respond to > "MyFaces Development" <dev@myfaces.apache.org> > > To > MyFaces Development <dev@myfaces.apache.org> > cc > Subject > Re: Custom component with children - Child component added > dynamically at end appears as first child when rendered > > > > > Hi Keerthi, > > Can you post your getter code for the navigation bar please? Make sure it > simply return null. My hunch is that your backing bean acts also as the > component factory (which can incredibly bad). > > > p.s. This post belong to the user list. Dev lists on Apache are for those > developing the product. You may be a developer, but from Apache MyFaces > perspective, you're an user. > > > Regards, > > ~ Simon > > On Tue, Oct 27, 2009 at 9:31 AM, > <*kpanneersel...@inautix.co.in*<kpanneersel...@inautix.co.in>> > wrote: > > I have a custom JSF component that renders navigation links. The following > is a typical usage of the component: > > <custom:navigationBar id="navbar" spacing="2" > actionListener="#{testBean.navigationLinkClicked}" immediate="true" > binding="#{testBean.navigationBar}"> > <custom:navigationLink id="primaryData" value="Primary Data"/> > <custom:navigationLink id="principals" value="Principals" > active="true"/> > <custom:navigationLink id="administrators" value="Administrators"/> > > <custom:navigationLink id="custodians" value="Custodians"/> > <custom:navigationLink id="accountingFirms" value="Accounting > Firms" clickable="false"/> > <custom:navigationLink id="lawFirms" value="Law Firms" > clickable="false"/> > <custom:navigationLink id="billing" value="Billing" > clickable="false"/> > </custom:navigationBar> > > And, the rendered content will appear as following: > > Primary Data | Principals | Administrators | Custodiams | Accounting Firms > | Law Firms | Billing > > > As you notice, the navigationBar component is bounded to > #{testBean.navigationBar} which is defined as below in the Backing bean: > > public class TestBean { > > private HtmlNavigationBar navigationBar; > .... // -- getter & setter for navigationBar > > public String formSubmitted() { > HtmlNavigationLink link = new HtmlNavigationLink(); > link.setId("link"); > link.setValue("New link"); > > navigationBar.getChildren().add(link) > > return null; > } > } > > > The backing bean has an action method formSubmitted() that adds a child > (HtmlNavigationLink) component to the parent (HtmlNavigationBar) > dynamically. This method is invoked on form submit. I thought that this > newly added child would be the last child (as it was added to end of the > children list). But, when the navigationBar renders its children, the > HtmlNavigationLink 'New link' appears as the first child causing the content > rendered as below: > > > New Link | Primary Data | Principals | Administrators | Custodiams | > Accounting Firms | Law Firms | Billing > > The following is the encodeChildren() method of *HtmlNavigationBar* > > @Override > public void encodeChildren(FacesContext context) throws IOException > { > ResponseWriter writer = context.getResponseWriter(); > List<UIComponent> children = getChildren(); > int count = children.size(); > > for (int i = 0; i < count; i++) { > UIComponent child = children.get(i); // -- why does > 'New link' appear at index == 0? > if (child instanceof HtmlNavigationLink) { > child.encodeAll(context); > } > } > } > > As noted in the comment above, while the child component was added to the > end of the list in the action method, it appears at index position 0 as the > first child? Why is it so? > > > >