1
votes

I have a AjaxFallbackDefaultDataTable table witch some text column (PropertyColumn). The table contains also a column with editable text fields. I'd like to update by AJAX one of the PropertyColumn, but I don't want to update the entire table. How can I do that?

1
Don't you mind sharing with us at least a relevant piece of your efforts - just in support of What have you tried? - Peter L.
We dont even know when you want to update that one column .. - Robert Niestroj
Robert, that is what I looking for (inter component Events). - Tomasz Fijałkowski

1 Answers

1
votes

If you use Wicket 6 you could use inter component Events.

First create an event which holds the AjaxRequestTarget like this:

public class AjaxUpdateEvent {
    private final AjaxRequestTarget target;

    public AjaxUpdateEvent(AjaxRequestTarget target) {
        this.target = target;
    }
    public AjaxRequestTarget getAjaxRequestTarget() {
        return target;
    }
}

You can send such an event form any Component you want using the send() method. You send events like this:

send(getPage(), Broadcast.DEPTH, new AjaxUpdateEvent(target));

Then in the AjaxFallbackDefaultDataTable i would try to override newCellItem and listen there for the event when fired from somewhere sometime and add the desired cell item to the AjaxRequestTarget. Something like that:

    AjaxFallbackDefaultDataTable table =
            new AjaxFallbackDefaultDataTable("table", null, null, FLAG_RESERVED1) {
        @Override
        protected Item newCellItem(String id, int index, IModel model) {
            Item item;
            if (index == indexOfColumnYouWant){
                item = new Item(id, index, model) {
                    @Override
                    public void onEvent(IEvent<?> event) {
                        super.onEvent(event); 
                        if ((event.getPayload() instanceof AjaxUpdateEvent) ){
                            ((AjaxRequestTarget)event.getPayload()).add(item);
                        }
                    }
                };
            } else {
                item = super.newCellItem(id, index, model);
            } 

            return item;
        }
    };

Additionally you could also add the item to the target if it isVisible().