Thanks for your response - there is no separate method to add children components (i.e. an 'addChildren()' or equivalent) - adding children is in fact done by adding a child component to the collection returned by getChildren(), the very method which I'm currently (and wrongly) overriding.
Your restoreState() option sounded interesting, but then I realized that upon first load of the page, restoreState() isn't called. That method is called, for example, on form submission. So on the first access of the page, if I'm correct the needed initialization wouldn't be done. Hmm, this is more difficult than I imagined - but such a common use case, so I'm hoping there's a clear, proper way to initialize JSF custom components. Martyn Hiemstra-3 wrote: > > You could change the part where the children are added to the form but > I'm not sure if this done using a method addChildren or via > getChildren().add(obj). If the last option is used then this will become > impossible. > You could also override the restoreState method in your form object and > first call the super class and then do your initialization of the > children. > > These are just some solutions from the top of my head so I haven't > tested them. These solutions would prevent you from overriding > getChildren which isn't a wise course of action. > > Martyn > > >> Where's the correct place to initialize a JSF custom component (in this >> case, >> a subclass of HtmlForm)? Because much of my initializing involves >> manipulating the component's children components, I decided to override >> getChildren() and do my initialization there - BAD IDEA! >> >> ...it turns out that getChildren() is called BEFORE restoreState(), so >> when >> you submit the form, restoreState isn't called and getChildren() fails >> because it's in an uninitialized state. >> >> I was thinking about using initializers or constructors, but then I >> figured >> to avoid it because some initialization could depend on the component >> properties getting populated first. (And initializers/constructors would >> be >> called before those properties get populated, via their setters.) >> >> It looks like I'm running out of options - what's the best practice on >> this? >> Thanks. >> > > > -- View this message in context: http://www.nabble.com/Difficulties-of-initializing-a-custom-component-tp22655436p22655676.html Sent from the MyFaces - Users mailing list archive at Nabble.com.

