tags:

views:

164

answers:

1

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(AjaxRequestTarget target) {

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

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 ;))

Tim
You shouldn't actually need the target.addComponent(panel) or the panel.setOutputMarkupId(true) at all, as these are handled inside the ModalWindow code.
Don Roby