I have a simple, mysterious problem with a label and using ajax to show it.
public class ChecklistTemplateForm extends Form{
private static final long serialVersionUID = 1L;
private Label cantSaveLabel;
public ChecklistTemplateForm(String id) {
super(id);
cantSaveLabel = new Label("cantSaveLabel", "Name is not unique, enter another name and try saving again.");
cantSaveLabel.setVisible(false);
cantSaveLabel.setOutputMarkupId(true);
add(cantSaveLabel);
add(new AjaxButton("saveButton") {
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
target.addComponent(cantSaveLabel);
//here i do some stuff to decide if canSave is true or false
if (canSave){
setResponsePage(AdminCheckListPage.class);
}
else if (!canSave){
cantSaveLabel.setVisible(true);
System.out.println(canSave);
}
}
});
}
}
The funny thing is, is canSave is false, the System.out.print works but the cansavelabel never becomes visible. What am I missing?
You have to tell wicket that it should use a placeholder for you label because it can't update a component that doesn't exist in the markup.
cantSaveLabel.setOutputMarkupId(true);
cantSaveLabel.setOutputMarkupPlaceholderTag(true);
You can not update the Label via Ajax as it is not in the rendered page. The
cantSaveLabel.setVisible(false);
makes it so that the Label is not in the HTML. You would need to surround the Label with another component (WebMarkupContainer), call setOutputMarkupId(true) on this and add this container to the AjaxRequestTarget instaed of the label.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With