开发者

Wicket: Can I use a modal Panel with a AjaxFallbackButton?

开发者 https://www.devze.com 2022-12-19 19:20 出处:网络
I have 2 inputs. When I press a button(AjaxFallbackButton), those inputs are saved into database. If one of the input is greater than 10, when I press the button, I want to show a modal panel, for as

I have 2 inputs. When I press a button(AjaxFallbackButton), those inputs are saved into database.

If one of the input is greater than 10, when I press the button, I want to show a modal panel, for asking the user if is the sure about his option. But the modal component is not appearing. Any thoughts?

 @Override
     public void onSubmit(AjaxRequestTarget target) {

  if (input < 10) { //save to database
} else {
         AskingDialogPanel panel = new AskingDialogPanel("content",
       new ResourceModel("asking.title"),
       new ResourceModel("asking.message")) {
      @Override
      public void onOkClick(AjaxRequestTarget target) {
       super.onOkClick(target);

                                                    //save to database
       modalWindow.close(target);
      }

      @Override
      public void onCancelClick(AjaxReques开发者_开发知识库tTarget target) {

       super.onCancelClick(target);
       modalWindow.close(target);
      }
     };
                                    panel.setOutputMarkupId(true);
                target.addComponent(panel);
                modalWindow.setContent(panel);
                modalWindow.show(target);
}


Have a look at the documentation for the AjaxRequestTarget.

A component whose markup needs to be updated should be added to this target via AjaxRequestTarget#addComponent(Component) method. Its body will be rendered and added to the envelope when the target is processed, and refreshed on the client side when the ajax response is received.

I'm not sure if I remember this correctly (I've had trouble implementing the correct refresh behavior previously), but I believe you could only addComponent components that were previously added to the page, but not rendered / invisible. These will than be updated and/or their visibility re-evaluated.

I could be wrong however.. Does the above work if you substitute a normal Label for the AskingDialogPanel? (Just to verify I'm talking out the wrong end ;))

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号