我使用組合框/下拉菜單來選擇用戶語言。如果用戶更改了語言,我想更新所有標籤,但只保留輸入元素。Wicket:如何在不丟失現有輸入的情況下恢復當前表單?
在jQuery中,我會要求標籤的ID,並通過JSON的新法規的清單,然後使用這樣的循環:
var texts = {[ {id:'nameLabel', text:'First Name'}, {id:'familyLabel', text:'Family Name'} ]};
for(var i=0; i<texts.length; i++) {
var item = texts[i];
$('#'+item.id).text(item.text);
}
這將更新所有標籤,而無需修改任何東西。我怎樣在Wicket上做到這一點?
[編輯]我想什麼:
DropDownChoice<Locale> ddc = new DropDownChoice<Locale>(...);
ddc.add(new AjaxFormComponentUpdatingBehavior("onchange") {
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
getSession().setLocale(language);
for(MarkupContainer label : labels) {
target.addComponent(label);
}
}
});
這確實改變了標籤,但它也再次呈現所有輸入字段。我發現無法訪問輸入字段的當前值。
[EDIT2]標籤的列表中創建像這樣:
StringResourceModel usernameLabel = new StringResourceModel("usernameLabel", this, new Model<ValueMap>(map));
labels.add(add(new Label("usernameLabel", usernameLabel)));
在這一行:'爲(MarkupContainer標籤:標籤)'什麼是標籤,你怎麼弄的? – 2010-12-16 13:37:42
標籤是頁面上所有標籤的列表。代碼見EDIT2。 – 2010-12-16 17:27:31