When running my program, I am trying to dynamically add Panels to the main page and utilize "setVisible(boolean)" functionality. However, I am encountering an error:
ERROR: Cannot bind a listener for event "click" on element "institutCheck7" because the element is not in the DOM
In the Ajax Debugger.
I found that this issue relates to visibility in this post. Although it mentions the problem being resolved in Wicket 7, I am currently using version 6.20.
adminUIForm.add(myPanel = new MyPanel("myPanel", allThings));
myPanel.setOutputMarkupId(true);
myPanel.setVisible(false);
//Note: Setting the OutputMarkupId allows actions such as setting components visible/invisible
List<IColumn<ContactInfo, String>> columns = new ArrayList<IColumn<ContactInfo, String>>();
columns = initializeColumns(columns);
DataTable<ContactInfo, String> datatable = new DataTable<ContactInfo, String>("datatable", columns, provider, 10){
private static final long serialVersionUID = 1L;
@Override
protected Item<ContactInfo> newRowItem(final String id, final int index,
final IModel<ContactInfo> model) {
Item<ContactInfo> rowItem = new Item<ContactInfo>(id, index, model);
rowItem.add(new AjaxEventBehavior("onclick") {
private static final long serialVersionUID = 1L;
@Override
protected void onEvent(AjaxRequestTarget target) {
System.out.println("click");
myPanel.setSelectedKontakt(model);
myPanel.setVisible(true);
target.add(myPanel);
}
});
return rowItem;
}
};
setTableProperties(datatable);
adminUIForm.add(datatable);
}
I have overridden the newRowItem method to include an onClick event. The console logs "click" each time a column is clicked, but I am receiving the following error:
ERROR: Wicket.Ajax.Call.processComponent: Component with id [[institutTablePanel6]] was not found while trying to perform markup update. Make sure you called component.setOutputMarkupId(true) on the component whose markup you are trying to update.
Several errors related to binding listeners for click events on elements like institutCheck7, cont8, etc., because they are not in the DOM.
All these errors seem to involve components within "myPanel," and I am unsure how to address this. Even if I set them to be visible earlier, I encounter the same issue, including elements that will later be hidden in the workflow.
Edit:
public class MyPanel extends Panel {
private static final long serialVersionUID = 1L;
private Form<Void> institutForm = new Form<Void>("institutForm");
private ListView<Institut> listView;
private IModel<ContactInfo> selectedKontakt;
private Set<Institut> allInstitut;
@Override
protected void onModelChanged() {
super.onModelChanged();
}
public InstitutTablePanel(String id, final Set<Institut> allInstitut) {
super(id);
this.allInstitut = allInstitut;
this.add(institutForm);
List<Institut> allInstitutList = new ArrayList<Institut>(allInstitut);
institutForm.add(listView = new ListView<Institut>("listView", allInstitutList) {
private static final long serialVersionUID = 1L;
protected void populateItem(final ListItem<Institut> item) {
final IModel<Boolean> checked = Model.of(Boolean.FALSE);
final IModel<String> expandState = Model.of("+");
@SuppressWarnings("unused")
final Label institutLabel;
final Institut institut = item.getModelObject();
final WebMarkupContainer div = createMarkUpContainer("cont");
final WebMarkupContainer container = createMarkUpContainer("container");
container.setEnabled(false);
compareInstitute(checked, institut, container);
item.add(container);
div.add(new AjaxEventBehavior("onclick") {
private static final long serialVersionUID = 1L;
@Override
protected void onEvent(AjaxRequestTarget target) {
expandOrCollapse(expandState, container);
target.add(institutForm);
}
});
item.add(div);
div.add(new AjaxCheckBox("institutCheck", checked) {
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
target.add(institutForm);
}
});
container.add(new ErhebungMatrixPanel("erhebungMatrix", institut, selectedKontakt));
container.setVisible(false);
div.add(institutLabel = new Label("institutLabel", new PropertyModel<Institut>(institut, "langName")));
}
});
listView.setOutputMarkupId(true);
listView.setReuseItems(true);
institutForm.setOutputMarkupId(true);
}}
I updated my setSelectedKontakt method to trigger changes:
public void setSelectedKontakt(IModel<ContactInfo> model) {
this.selectedKontakt = model;
modelChanged();
}
The issue lies in target.add(myPanel);
not triggering populateItem again.