Why not use findParent(Form.class)? Or pointer.findParent(Form.class)? A method like onParentAssigned would only partially solve the problem, as that gives no guarantees to the parents of the parents. It'll get even messier probably. Furthermore, we don't need it in 2.0 anymore, as in 2.0 the hierarchy is known at construction time.
Eelco > Hi , the below is the method that I thought , > I think it can combine form.add(myDatePicker) and > form.add(myDatePickerValidator) > > > public class MyDatePicker extends Panel > { > private boolean validatorAdded = false; > ....................... > .... skipped....... > ...................... > > @Override > protected void onBeforeRender() > { > super.onBeforeRender(); > > if (!validatorAdded) > { > MarkupContainer pointer = this; > while (pointer.getParent() != null) > { > MarkupContainer markupContainer = pointer.getParent (); > if (markupContainer instanceof Form) > { > Form form = (Form) markupContainer; > form.add(new MyDatePickerValidator(this)); > validatorAdded=true; > break; > } > pointer = pointer.getParent(); > } //while > } //if > } //onBeforeRender() > } //class > > By this way , other programmers just need form.add(myDatePicker) , doesn't > need to know it needs other validators. > I think it is a little tricky (and dumb) , but I cannot find other ways to > solve this. > > Any better idea ? > > BTW , I suggest the following method : > > Compoment.onParentAssigned(Compoment parent); > If there is this method , I can easily solve this problem , needn't to do > the tricky onBeforeRender()... > > > > > _______________________________________________ > Wicket-user mailing list > Wicket-user@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/wicket-user > > > _______________________________________________ Wicket-user mailing list Wicket-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wicket-user