How can I update a Wicket DataView with AJAX?

二次信任 提交于 2019-12-12 04:39:26

问题


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?


回答1:


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);
    }


来源:https://stackoverflow.com/questions/4561045/how-can-i-update-a-wicket-dataview-with-ajax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!