start with something simple like creating a reusable datetextfield

private static class DateField extends DateTextField {
  public DateField(String id, IModel model) {
        super(id, model, "MM/dd/yyyy");
        setrequired(true);
        setoutputmarkupid(true);
   }
}

this will change the code down to:

   private void addReservationDates()
   {
       // create the feedback panel
       FeedbackPanel feedback = new FeedbackPanel("feedback");
       feedback.setOutputMarkupId(true);
       add(feedback);

       // create the check-in field
       DateField checkIn = new DateField("checkIn");
       checkIn.add(DateValidator.minimum(getToday()));
       add(buildAjaxFeedbackBorder("checkInBorder", checkIn, feedback));


        // create a date picker for the check-in field
        add(new CylleniusCalendar("checkInPicker", checkIn));

        // create the check-out field
        DateField checkOut = new DateField("checkOut");
        add(buildAjaxFeedbackBorder("checkOutBorder", checkOut,
feedback));

        // create a date picker for the check-out field
        add(new CylleniusCalendar("checkOutPicker", checkOut));

        // require checkIn to be before checkOut
        add(new DatesComparatorValidator(checkIn, checkOut));
    }

    private FormComponentFeedbackBorder buildAjaxFeedbackBorder(String
borderId,
            FormComponent component, final FeedbackPanel feedback)
    {
       ...
    }



then externalize the feedback border, and make it reusable for the entire
project

class myajaxerrorborder extends formcomponentfeedbackborder {
 private boolean initialized=false;
  public myajaxerroborder(String id) {
       super(id);
       setoutputmarkupid(true);
   }

  protected void onattach() {
      super.onattach();
      if (!initialized) {
         foreach child of type formcomponent in border's hierarchy // use a
visitor {
             child.add(new formcomponentupdatingbehavior() {
                          onerror(target) {
                               target.addcomponent(myajaxerrorborder.this);
                               foreach feedbackpanel in getPage()'s
hierarchy {
                                       target.add(feedbackpanel);
                               }
                           }
              }
         }
        initialized=true;
    }
}

so the above border automatically initializes form component children you
add to its hierarchy, it doesnt handle children added after the first
request but it is simple to make it do that, i leave that as an exercise to
you :)

so now we are at:


   private void addReservationDates()
   {
       // create the feedback panel
       add(new FeedbackPanel("feedback").setOutputMarkupId(true));

       // create the check-in field

       DateField checkIn = new DateField("checkIn");
       checkIn.add(DateValidator.minimum(getToday()));
       add(new MyAjaxErrorBorder("checkInBorder").add(checkIn));


        // create a date picker for the check-in field
        add(new CylleniusCalendar("checkInPicker", checkIn));

        // create the check-out field
        DateField checkOut = new DateField("checkOut");
        add(new MyAjaxErrorBorder("checkOutBorder").add(checkOut));

        // create a date picker for the check-out field
        add(new CylleniusCalendar("checkOutPicker", checkOut));

        // require checkIn to be before checkOut
        add(new DatesComparatorValidator(checkIn, checkOut));
    }


now convert the datepicker from a panel to a behavior - pretty easy to do,
in fact eelco will be doing that today? to wicket-datetime datepicker

so now you will have

private static class DateField extends DateTextField {
  public DateField(String id, IModel model) {
        super(id, model, "MM/dd/yyyy");
        setrequired(true);
        setoutputmarkupid(true);
       add(new CelleniusDatepicker());
   }
}

private void addReservationDates()
   {
       // create the feedback panel
       add(new FeedbackPanel("feedback").setOutputMarkupId(true));

       // create the check-in field

       DateField checkIn = new DateField("checkIn");
       checkIn.add(DateValidator.minimum(getToday()));
       add(new MyAjaxErrorBorder("checkInBorder").add(checkIn));


        // create the check-out field
        DateField checkOut = new DateField("checkOut");
        add(new MyAjaxErrorBorder("checkOutBorder").add(checkOut));

        // require checkIn to be before checkOut
        add(new DatesComparatorValidator(checkIn, checkOut));
    }


finally extract a simple daterange panel like jon suggested

and you will be down to:

private void addReservationDates()
   {
       // create the feedback panel
       add(new FeedbackPanel("feedback").setOutputMarkupId(true));

       add(new DateRangeSelector("selector", new PropertyModel(this,
"checkIn"), new PropertyModel(this, "checkOut"), getToday(), null));
}

and what you end up with are new reusable

datefield
ajax error border
daterange selector

that you can use anywhere in your project

this is where you really win out over jsf/tapestry

if you dont mind this might make a good wiki page, but it needs to be
cleaned up lots :)

-igor


On 2/8/07, Scott Swank <[EMAIL PROTECTED]> wrote:

Igor,

The most verbose code is the following.  It creates the FeedbackPanel and
two fields: a check-in date and a check-out date.  The comments are a bit
heavy because this is a proof-of-concept app.  At this point, and such "best
practices" pointers are more than welcome.  Thank you.

...Oh, and the CylleniusCalendar (our underlying app is named Cyllenius)
is simply a sub-class of DatePicker with a HeaderContributor.forCss() to
increase its z-index a a value greater than that of the ModalWindow from
which it is opened.

    private void addReservationDates()
    {
        // create the feedback panel
        FeedbackPanel feedback = new FeedbackPanel("feedback");
        feedback.setOutputMarkupId(true);
        add(feedback);

        // create the check-in field
        DateTextField checkIn = new DateTextField("checkIn", new
PropertyModel(roomRequest, "checkIn"),
                "MM/dd/yyyy");
        checkIn.setOutputMarkupId(true);
        checkIn.setRequired(true);
        checkIn.add(DateValidator.minimum(getToday()));
        add(buildAjaxFeedbackBorder("checkInBorder", checkIn, feedback));

        // create a date picker for the check-in field
        add(new CylleniusCalendar("checkInPicker", checkIn));

        // create the check-out field
        DateTextField checkOut = new DateTextField("checkOut", new
PropertyModel(roomRequest,
                "checkOut"), "MM/dd/yyyy");
        checkOut.setOutputMarkupId(true);
        checkOut.setRequired(true);
        add(buildAjaxFeedbackBorder("checkOutBorder", checkOut,
feedback));

        // create a date picker for the check-out field
        add(new CylleniusCalendar("checkOutPicker", checkOut));

        // require checkIn to be before checkOut
        add(new DatesComparatorValidator(checkIn, checkOut));
    }

    private FormComponentFeedbackBorder buildAjaxFeedbackBorder(String
borderId,
            FormComponent component, final FeedbackPanel feedback)
    {
        final FormComponentFeedbackBorder border = new
FormComponentFeedbackBorder(borderId);
        border.add(component);
        border.setOutputMarkupId(true);

        component.add(new AjaxFormComponentUpdatingBehavior("onblur") {
            private static final long serialVersionUID =
-8868206053122717303L;

            protected void onUpdate(AjaxRequestTarget target)
            {
                target.addComponent(feedback);
                target.addComponent(border);
            }
        });

        return border;
    }

On 2/7/07, Igor Vaynberg <[EMAIL PROTECTED]> wrote:

> On 2/7/07, Scott Swank <[EMAIL PROTECTED]> wrote:
> >
> > 2. Overall there was a preference for Wicket's Java components over
> > JSF's taglibs and backing bean code.  This was not a unanimous preference,
> > and taglibs are much more concise than Wicket code.  However, the cleanness
> > of the resulting HTML was a factor in Wicket's favor and the rapidity of the
> > development effort largely offset the comparative verbosity of the code
> > base.  This verbosity was most evident in ajax form feedback: feedback
> > panel, text field, ajax feedback border, ajax behavior, etc.
>
>
> got any examples of this verbouse code? i am doing something similar in
> a project i am building with 2.0 and i was able to factor out a lot of
> this stuff so its not so bad. maybe we can help you do the same.
>
> -igor
>
>
>
>
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services,
> security?
> Get stuff done quickly with pre-integrated technology to make your job
> easier.
> Download IBM WebSphere Application Server v.1.0.1 based on Apache
> Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Wicket-user mailing list
> Wicket-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/wicket-user
>
>


--
Scott Swank
reformed mathematician
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job
easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to