我创建了一个面板,我在其中尝试将实时 Ajax 行为应用于某些单选选项。
问题是我无法设置当前的活动选项,在设置器“setSelectedLang”中,参数总是为空,即使我点击不同的单选选项。这怎么能解决?
我正在运行 Wicket 7.5.0 版。
package xx.yy.admin
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormChoiceComponentUpdatingBehavior;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.RadioChoice;
import org.apache.wicket.markup.html.panel.GenericPanel;
import org.apache.wicket.model.PropertyModel;
import xx.yy.admin.Survey;
import xx.yy.admin.AjaxListener;
import java.util.Arrays;
import java.util.List;
public class LanguageSelectionPanel extends GenericPanel<Void> {
private static final String SVENSKA = "Sve";
private static final String ENGELSKA = "Eng";
private AjaxListener listener;
private Form<Void> form;
private List<String> languages = Arrays.asList(SVENSKA, ENGELSKA);
private Survey surveyModel;
private String selectedLang = "Sve";
private RadioChoice languageRadioChoice;
public SurveyLanguageSelectionPanel(String id, Survey survey, AjaxListener listener) {
super(id);
this.surveyModel = survey;
this.listener = listener;
initialize();
}
protected void initialize() {
super.onInitialize();
form = new Form<Void>("langform") {
@Override
protected void onSubmit() {
info("Init : ");
}
};
add(form);
languageRadioChoice = getLanguageSelection();
form.add(languageRadioChoice);
}
private RadioChoice getLanguageSelection() {
RadioChoice<String> langRadioChoice = new RadioChoice<>("languages",
new PropertyModel<>(this, "selectedLang"), languages);
// Add Ajax Behaviour...
langRadioChoice.add(new AjaxFormComponentUpdatingBehavior("onchange") {
protected void onUpdate(AjaxRequestTarget target) {
listener.onUpdate(target);
}
});
return langRadioChoice;
}
public void setSelectedLang(String selectedLang) {
this.selectedLang = selectedLang;
}
public String getSelectedLang() {
return selectedLang;
}
}
html代码:
<body>
<wicket:panel>
<form style="" class="" wicket:id="langform">
<wicket:enclosure child="languages">
<span wicket:id="languages"></span>
</wicket:enclosure>
<br/>
<hr/>
</form>
</wicket:panel>
</body>
</html>