Reputation: 934
There is input text field and submit button. I would like to show button text field not empty and otherwise button should be not visible.
TextArea<String> textMessageField = new TextArea<>("textMessage", textMessageModel);
Button submitBtn = new Button("saveReminderButton") {
@Override
protected void onConfigure() {
super.onConfigure();
String text = textMessageField.getModelObject();
setVisible(text != null && !text.isEmpty());
}
};
textMessageField.add(new OnChangeAjaxBehavior() {
@Override
protected void onUpdate(AjaxRequestTarget target) {
target.add(submitBtn);
}
});
submitBtn.setOutputMarkupId(true);
I'm trying to use setVisible
method in onConfigure
but it doesnt work. I tried to use instead setEnabled
and it was working but I need the same functionality with hide/show button
Upvotes: 0
Views: 186
Reputation: 17503
Since you make the button invisible you need to use submitBtn.setOutputMarkupPlaceholderTag(true);
instead of submitBtn.setOutputMarkupId(true);
This is important because without setOutputMarkupPlaceholderTag(true)
Wicket Wicket will render nothing for this component. With setOutputMarkupPlaceholderTag(true)
it will render <htmlElement id="someId"></htmlElement>
. This way Wicket Ajax could find it in the DOM and replace it with the HTML of the visible one.
Upvotes: 3