2
我有一个AjaxEditableLabel
如何让AjaxEditableLabel显示TextField?
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;
}
};
谢谢,我在原文中添加了修改后的'AjaxEditableLabel'。 – 2011-06-10 09:45:45