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