Java 如何隐藏WebMarkUpContainer在Wicket中检查AjaxCheckBox
好的,基本上我有一个WebMarkUpContainer,它包含一个DateTextField组件,我想让它只有在我选中AjaxCheckBox时才可见 一般来说,我的代码是:Java 如何隐藏WebMarkUpContainer在Wicket中检查AjaxCheckBox,java,ajax,wicket,Java,Ajax,Wicket,好的,基本上我有一个WebMarkUpContainer,它包含一个DateTextField组件,我想让它只有在我选中AjaxCheckBox时才可见 一般来说,我的代码是: private static final class Results extends BootstrapForm<ResultsModel> { final AjaxCheckBox isExamsSuccess = new AjaxCheckBox("isExamsSuccess") {
private static final class Results extends BootstrapForm<ResultsModel>
{
final AjaxCheckBox isExamsSuccess = new AjaxCheckBox("isExamsSuccess") {
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
updateModel();
toggleStep(target);
}
};
final WebMarkupContainer wmc = new WebMarkupContainer("wmc");
final DateTextField startDate = new DateTextField("startDate",
new DateTextFieldConfig()
.autoClose(true).withFormat("dd/MM/yyyy")
.withLanguage("el").withEndDate(new DateTime()));
public Results(String id, CompoundPropertyModel<ResultsModel> propertyModel)
{
super(id, propertyModel);
add(isExamsSuccess);
wmc.add(startDate);
add(wmc);
protected void toggleStep(AjaxRequestTarget target) {
if(isExamsSuccess.getModelObject() == true){
isExamsSuccess.setModelObject(true);
wmc.setVisible(true);
target.add(wmc);
}
else {
wmc.setVisible(false);
target.add(wmc);
}
}
}
private静态最终类结果扩展了BootstrapForm
{
最终AjaxCheckBox IsexamSuccess=新AjaxCheckBox(“IsexamSuccess”){
私有静态最终长serialVersionUID=1L;
@凌驾
受保护的void onUpdate(AjaxRequestTarget目标){
updateModel();
切换步骤(目标);
}
};
最终WebMarkupContainer wmc=新的WebMarkupContainer(“wmc”);
final DateTextField startDate=新的DateTextField(“startDate”,
新建DateTextFieldConfig()
.autoClose(true).withFormat(“dd/MM/yyyy”)
.withLanguage(“el”)。withEndDate(新日期时间());
公共结果(字符串id、CompoundPropertyModel propertyModel)
{
super(id,propertyModel);
添加(isExamsSuccess);
wmc.add(起始日期);
添加(wmc);
受保护的无效切换步骤(AjaxRequestTarget目标){
if(isExamsSuccess.getModelObject()==true){
isExamsSuccess.setModelObject(true);
wmc.setVisible(真);
target.add(wmc);
}
否则{
wmc.setVisible(假);
target.add(wmc);
}
}
}
我非常感谢您的帮助您的代码看起来不错!您只需将
wmc
的初始可见性设置为依赖于isexamsuccess
:
wmc = new WebMarkupContainer("wmc") {
@Override public void onConfigure() {
super.onConfigure();
setVisible(isExamsSuccess.getModelObject());
}
}
wmc.setOutputMarkupPlaceholderTag(true);
此外,您需要调用setOutputMarkupPlaceholderTag(true)
,因为Wicket需要能够找到HTML元素,以便将可见性从关闭
转到打开