- AbstractAjaxTimerBehavior
- AjaxEventBehavior
- AjaxFormComponentUpdatingBehavior
A behavior that generates an AJAX update callback at a regular interval. java doc
WicketComponenet.add(new AbstractAjaxTimerBehavior(Duration.milliseconds(300)){ @Override protected void onTimer(AjaxRequestTarget target) { // TODO Auto-generated method stub System.out.println("ajax here!"); target.add(ComponentToModify); }});
An ajax behavior that is attached to a certain client-side (usually javascript) event, such as onClick, onChange, onKeyDown, etc. Example:
WebMarkupContainer div=new WebMarkupContainer(...); div.setOutputMarkupId(true); div.add(new AjaxEventBehavior("onclick") { protected void onEvent(AjaxRequestTarget target) { System.out.println("ajax here!"); } }This behavior will be linked to the onclick javascript event of the div WebMarkupContainer represents, and so anytime a user clicks this div the onEvent(AjaxRequestTarget) of the behavior is invoked. Java doc
If you have a form component in wicket with some components and you want to change using ajax some things in that form before submit (when you click or edit on one of the components), then you have to use AjaxFormComponentUpdatingBehavior. This is a behavior that updates the hosting FormComponent via ajax when an event it is attached to is triggered.
WicketComponenet.add(new AjaxFormComponentUpdatingBehavior("onchange"){ @Override protected void onUpdate(AjaxRequestTarget target){ // TODO System.out.println("ajax here!"); target.add(ComponentToModify); }}.setThrottleDelay(Duration.seconds(1)) ); ComponentToModify.setOutputMarkupId( true );
The key is that your component must be a FormComponent, otherwise the event won't be triggered. Simple components like CheckBox, TextField, DropDownChoice are all FormComponents. Java Doc you should be careful to set setOutputMarkupId(true) of the component that will be modified after defining the behavior !
Aucun commentaire:
Enregistrer un commentaire