2006/6/13, Eelco Hillenius <[EMAIL PROTECTED]>:
> I thought this way has some flaw , because it decoupled myDatePicker and
> myDatePickerValidator ,
> Other programmer may form.add(myDatePicker); and forget to
> form.add(myDatePickerValidator);

You can hide adding that validator in your component too. Of course,
the idea is that you hide everything that has to do with that
component in that component. Encapsulation, baby!


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

Reply via email to