我有我要显示的字符串变量

final String wrongPw = "Wrong Password";

我的AJAX是按钮:

AjaxButton yesButton = new AjaxButton("yesButton", yesNoForm) {
        private static final long serialVersionUID = -3827487963204274386L;
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form form) {
            if (target != null && password.equals(getPw())) {
                answer.setAnswer(true);
                modalWindow.close(target);
            }else if(target != null && !password.equals(getPw())){
                answer.setAnswer(false);
                wrongPW.setVisible(true);
            }
        }
    };


再向下:

wrongPW.setVisible(false);
add(wrongPW);


当我点击是按钮时,我必须刷新页面以显示wrongPW

如何动态地做到这一点?

最佳答案

您必须像这样将要更新的组件添加到目标:

target.add(wrongPW);


确保在要动态更改其可见性的组件初始化时设置标记占位符标签,否则Wicket将找不到它。

wrongPW.setOutputMarkupPlaceholderTag(true);


解释原因如下:https://stackoverflow.com/a/9671796/2795423

08-04 21:17