Wicket dynamic ListView - default item won't get updated by Ajax

mvheyl

I have a ListView starting with one item being displayed, where I append every new item with an AjaxSubmitLink, which works fine. Inside the ListView I have two DropDownChoices, the first triggering the choices of the second via AjaxFormComponentUpdatingBehavior. This works too, but only if I add another item to the default item. If the AjaxSubmitLink isn't clicked, the second DropDownChoice isn't updated, and in the Ajax debug window there is a blank instead of the id of the first DropDownChoice.

Here's my code:

final MarkupContainer devicescontainer = new WebMarkupContainer("devicesContainer");
devicescontainer.setOutputMarkupId(true);
add(devicescontainer);   
final ListView devicesListView = new ListView<Device>("devices", devices) {

    @Override
    protected void populateItem(ListItem<Device> item) {
        item.setModel(new CompoundPropertyModel<Device>(item.getModel()));
        final List<Device.DeviceCategory> cats = Arrays.asList(Device.DeviceCategory.values());
        final DropDownChoice<Device.DeviceCategory> categoryDropDownChoice = new DropDownChoice<Device.DeviceCategory>("deviceCategory", cats);
        final DropDownChoice<Device.DeviceSubcategory> subcategoryDropDownChoice = new DropDownChoice<>("deviceSubcategory");
        categoryDropDownChoice.setOutputMarkupId(true);
        subcategoryDropDownChoice.setOutputMarkupId(true);

        categoryDropDownChoice.add(new AjaxFormComponentUpdatingBehavior("change") {
            @Override
            protected void onUpdate(AjaxRequestTarget target) {
                List<Device.DeviceSubcategory> subcats = Device.getPotentialSubcategories(categoryDropDownChoice.getModelObject());
                subcategoryDropDownChoice.setChoices(subcats);
                target.add(subcategoryDropDownChoice);
        }});
        item.add(categoryDropDownChoice);
        item.add(subcategoryDropDownChoice);
    }
}.setReuseItems(true);
devicescontainer.add(devicesListView);

AjaxSubmitLink addDeviceLink = new AjaxSubmitLink("addDevice") {

    @Override
    public void onSubmit(AjaxRequestTarget target, Form form) {

        devicesListView.getModelObject().add(new Device(newId));
            if (target != null){
                target.add(devicescontainer);
            }
    }
};
addDeviceLink.setDefaultFormProcessing(false);
devicescontainer.add(addDeviceLink);

How do I get the Ajax powered DropDownChoice to work without first clicking the Add device link?

Edit: The generated ids of all the elements are complete and unique. The ListView items don't have ids, and it doesn't help if they do.

mvheyl

Turns out it was in fact the corporate JavaScript that caused the problem. I believe it calls the select2 jquery plugin on the <select>s and such the Ajax gets overriden. I just removed the entire script and now everything works fine.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

ListView item won't change its backgroundColor in onCreate, but it does onItemClick

From Dev

jQuery Ajax GET request won't cache

From Dev

Hiding Wicket WebMarkupContainer won't work

From Dev

Hiding Wicket WebMarkupContainer won't work

From Dev

wicket refresh listView in different panel using ajax

From Dev

View doesn't get updated when item is added to array

From Dev

Fullpage.js navigation one item won't get active

From Dev

Apache Wicket: React on Ajax Request Before Model is Updated

From Dev

Dynamic ListView Item Not Populating XML

From Dev

Get the value of the Item in the Listview

From Dev

Get ListView item properties

From Dev

Observe @each and get updated item

From Java

Flutter ListView won't Update

From Dev

ListView won't scroll vertically

From Dev

Included ListView won't Populate

From Dev

ListView won't scroll vertically

From Dev

ListView won't update onNewIntent()

From Dev

Can't get selected item text from ListView

From Dev

Item won't update in database

From Dev

Dynamic SQL won't execute

From Dev

My getters won't give an updated variable

From Dev

dataGridView won't reflect updated dataset

From Dev

Swift Mailer won't use updated settings

From Dev

Dynamic ChartJS Chart Updated in Rails with AJAX

From Dev

Dynamic ChartJS Chart Updated in Rails with AJAX

From Dev

Watch for updated properties in Wicket

From Dev

Watch for updated properties in Wicket

From Dev

How to get column index of clicked column of listview that hasn't listview item?

From Dev

AJAX won't submit data