Daler
Daler

Reputation: 834

How can I update a Wicket DataView with AJAX?

I need to AJAXfully filter by users list of PsDoctrans which is shown in a Wicket DataView.

final TextField txtName= new TextField("user");

final PSDocDP dp = new PSDocDP("username");
DataView<PsDoctrans> dataView = new DataView<PsDoctrans>("unproc", dp)
{
    @Override
    protected void populateItem(final Item<PsDoctrans> item)
    ...
};

PSDocDP is:

public class PSDocDP extends SortableDataProvider<PsDoctrans>
{...}

final WebMarkupContainer wmc = new WebMarkupContainer("container"); 
wmc.add(dataView); 
wmc.setOutputMarkupId(true);

AjaxButton butFind=new AjaxButton("find"){
    @Override
    protected void onSubmit(AjaxRequestTarget target, Form<?> form)
    {               
        String value=(String)txtName.getModelObject();
        dp = new PSDocDP(value);

        target.addComponent(wmc);
    }
};

After submitting, nothing changes. The program shows some data, but it isn't filtering. How can I make filtering happen?

Upvotes: 0

Views: 4883

Answers (1)

mtraut
mtraut

Reputation: 4740

I use constructions comparable to this, so it should work.

Do you really create a new "dp" object in the callback. You should simply change the state of the data provider - how should the component ever get the changed provider.

    @Override
    protected void onSubmit(AjaxRequestTarget target, Form<?> form)
    {               
        String value=(String)txtName.getModelObject();
-->        dp.setName(value);
        target.addComponent(wmc);
    }

Upvotes: 2

Related Questions