I've started a new wiki page on this topic as it's come up a few times in the past. I've tried to organize it a little, but there's room for improvement, and likely a few errors as well, some of which I may have introduced in organizing it :)
http://wiki.apache.org/myfaces/Creating_Composite_Components On 11/7/05, Nico Krijnen <[EMAIL PROTECTED]> wrote: > Hi Mel, > > You can simply use the getChildren() method and add components to the list > you receive. > Maybe interesting for other people as well: I created a utility base class > that can simplify creation om composite components, see code below. > Extend your component from this class and implement the > readyToCreateChildComponents() and createChildComponents() methods. When you > want to recreate the child components (for example because the underlying > datamodel changed), you can call the invalidate() method on the component. > > Nico Krijnen > > > public abstract class BaseChildCreatorComponent extends UINamingContainer { > > /* > * Child component buildup > */ > > private boolean childrenValid = false; > > public void invalidate() { > childrenValid = false; > } > > private void validateChildren() { > if (!childrenValid) { > childrenValid = true; > List children = super.getChildren(); > children.clear(); > createChildComponents(children); > } > } > > protected abstract boolean readyToCreateChildComponents(); > > protected abstract void createChildComponents(List children); > > /* > * Child component rendering > */ > > public boolean getRendersChildren() { > return true; > } > > public void encodeChildren(FacesContext context) throws IOException > { > validateChildren(); > if (this.getChildCount() > 0) { > for (Iterator it = this.getChildren().iterator(); > it.hasNext();) { > UIComponent child = (UIComponent) it.next(); > RendererUtils.renderChild(context, child); > } > } > } > > /* > * State saving > */ > > public void restoreState(FacesContext context, Object state) { > Object values[] = (Object[]) state; > super.restoreState(context, values[0]); > childrenValid = ((Boolean) values[1]).booleanValue(); > } > > public Object saveState(FacesContext context) { > Object values[] = new Object[2]; > values[0] = super.saveState(context); > values[1] = new Boolean(childrenValid); > return ((Object) (values)); > } > > } > > -----Oorspronkelijk bericht----- > Van: TRIFILETTI, Mel [mailto:[EMAIL PROTECTED] > Verzonden: maandag 7 november 2005 9:35 > Aan: MyFaces Discussion > Onderwerp: Compound components made up other jsf components > > > Hi > > I've just completed my first simple component. Now I want to develop a > more complex component which will contain multiple instances of my first > component, which will be used as building blocks. > > > E.g. Component B will be made up of two Component A components. > > Having a look at the UIComponentBase I don't see any addChildren() > methods only getChildren()? I would expect that in the constructor of > Component B I could create and add my child components. > > Is what am I asking possible? Are they any articles on advanced > components? > > Mel > > > > > > > "DISCLAIMER: This email, including any attachments, is intended only for use > by the addressee(s) and may contain confidential and/or personal information > and may also be the subject of legal privilege. If you are not the intended > recipient, you must not disclose or use the information contained in it. In > this case, please let me know by return email, delete the message > permanently from your system and destroy any copies. > > > Before you take any action based upon advice and/or information contained in > this email you should carefully consider the advice and information and > consider obtaining relevant independent advice. > > >

