У меня есть AjaxEditableLabel
AjaxEditableLabel<String> task = new AjaxEditableLabel<String>("task", new PropertyModel<String>(getModel(), "task"));
Теперь, что я пытаюсь сделать, это при некоторых условиях это AjaxEditableLabel
будет отображаться как TextField
.По умолчанию он отображается как Label
.Скажите, если задание модели String
является пустым или пустым, AjaxEditableLabel
будет TextField
, иначе это будет Label
.
Возможно ли это?
Спасибо.
Редактировать:
AjaxEditableLabel<String> task = new AjaxEditableLabel<String>("task", new PropertyModel<String>(getModel(), "task")) {
private static final long serialVersionUID = 40L;
private TextField<String> editor;
protected FormComponent<String> newEditor(MarkupContainer parent, String componentId, IModel<String> model) {
editor = (TextField<String>) super.newEditor(parent, componentId, model);
Object modelObject = getDefaultModelObject();
if (modelObject == null || "".equals(modelObject)) {
editor.setVisible(true);
} else {
editor.setVisible(false);
}
return editor;
}
protected WebComponent newLabel(MarkupContainer parent, String componentId, IModel<String> model) {
Label label = (Label) super.newLabel(parent, componentId, model);
if (editor.isVisible()) {
label.setVisible(false);
}
return label;
}
};