You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Gianni Doe <gd...@yahoo.it> on 2008/11/03 15:02:53 UTC
Add AJAX behaviour to embedded custom form component
I've developed a custom form component (FormComponentPanel), a date
picker, that makes use of 2 fields - a display TextField and a
HiddenField for the model data. I'm then adding this to the page with
a span tag:
<span wicket:id="dropoffDate">[dropoff date picker]</span>
Then in the java :
DatePicker dropoffDatePicker = new DatePicker("dropoffDate", new
PropertyModel<LocalDate>(this, "dropoffDate"),
(new LocalDate()).minusDays(0), (new
LocalDate()).plusYears(3));
I'm after some advice on the best way to attach an AJAX behaviour to
the component. If for example I add an AJAX behaviour directly to the
date picker component then it's attached to the span tag and obviously
doesn't work. The only way I've found to get around this is to expose
the date display field with a public getter so I can then attach the
onchange event.
dropoffDatePicker.getDateDisplayField().add(new
AjaxFormComponentUpdatingBehavior("onchange") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
......
}
});
Any suggestions for a better way to do this that doesn't involve
exposing the innards?
-Gianni
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Add AJAX behaviour to embedded custom form component
Posted by Igor Vaynberg <ig...@gmail.com>.
a better way is to have a factory method for the internal components,
that way the user can do
component newcomponent(string id, imodel model) {
component c=super.newcomponent(id, model);
c.add(whateverbehavior);
return c;
}
-igor
On Mon, Nov 3, 2008 at 6:02 AM, Gianni Doe <gd...@yahoo.it> wrote:
> I've developed a custom form component (FormComponentPanel), a date picker,
> that makes use of 2 fields - a display TextField and a HiddenField for the
> model data. I'm then adding this to the page with a span tag:
> <span wicket:id="dropoffDate">[dropoff date picker]</span>
>
> Then in the java :
> DatePicker dropoffDatePicker = new DatePicker("dropoffDate", new
> PropertyModel<LocalDate>(this, "dropoffDate"),
> (new LocalDate()).minusDays(0), (new
> LocalDate()).plusYears(3));
>
> I'm after some advice on the best way to attach an AJAX behaviour to the
> component. If for example I add an AJAX behaviour directly to the date
> picker component then it's attached to the span tag and obviously doesn't
> work. The only way I've found to get around this is to expose the date
> display field with a public getter so I can then attach the onchange event.
>
> dropoffDatePicker.getDateDisplayField().add(new
> AjaxFormComponentUpdatingBehavior("onchange") {
> @Override
> protected void onUpdate(AjaxRequestTarget target) {
> ......
> }
> });
>
> Any suggestions for a better way to do this that doesn't involve exposing
> the innards?
> -Gianni
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org