I have the following hierarchy:

MyPage
  MyDataView
  ModalWindow (containing a MyModalPage)
    MyModalPage
      MyModalForm
        AjaxSubmitLink

The modal window is used to add new items to MyDataView.

If there are errors when the form is submitted, the modal window
should stay open with feedback inside it.  I have that working.

If the submit is successful, I want MyDataView on MyPage to refresh.
I see two ways to do that:

1.  Somehow refresh the entire page with setResponsePage or some other means.
2.  Use AJAX to refresh just MyDataView

When I tried #1, the modal window didn't close and the contents of it
became the outer page (myPage).  So the modal windows contained the
content of the outer page.

            add(new AjaxSubmitLink("submit",this)
            {
                protected void onSubmit(AjaxRequestTarget target, Form form) {
                        target.addComponent(feedback);
                        window.close(target);
                        myPage.setResponsePage(myPage);
                }
            });

When I tried #2, the form submitted properly, but myDataView didn't refresh.

            add(new AjaxSubmitLink("submit",this)
            {
                protected void onSubmit(AjaxRequestTarget target, Form form) {
                        target.addComponent(feedback);
                        target.addComponent(myPage.getMyDataView());
                        window.close(target);
                }
            });

I don't know if myPage.getMyDataView() will work in this way since
myPage is private field of MyModalPage that accesses a getter for a
private field of MyPage called myDataView. I did
setOutputMarkupId(true) on it.

What is the best way to accomplish this? Below is the pertinent code.

Thanks,
Tauren

----

public class MyPage extends UserBasePage {
    private DataView myDataView;
        
    public MyPage() {
        super();
        MyDataProvider dp = new MyDataProvider();
        myDataView = new DataView("dataview", dp)
                {
                     ....
                };
        myDataView.setOutputMarkupId(true);
        myDataView.setItemsPerPage(40);
        add(myDataView);

        final ModalWindow newService;
        add(newService = new ModalWindow("newService"));
        newService.setPageMapName("newService");
        newService.setCookieName("newService");
        newService.setPageCreator(new ModalWindow.PageCreator()
        {
            public Page createPage()
            {
                return new MyModalPage(MyPage.this, newService);
            }
        });
   }
   public DataView getMyDataView() ...
   public void setMyDataView(DataView myDataView) ...
}

public class MyModalPage extends WebPage {

private FeedbackPanel feedback;
private MyPage myPage;
private ModalWindow window;

public MyModalPage(final MyPage myPage, final ModalWindow window)
{
        this.myPage = myPage;
        this.window = window;
        feedback = new FeedbackPanel("feedback");
        feedback.setOutputMarkupId(true);
        add(feedback);
        Form form = new MyModalForm("form");
        add(form);
}

public class MyModalForm extends Form {
        public MyModalForm(String id){
              ...
            add(new AjaxSubmitLink("submit",this)
            {
                @Override
                protected void onSubmit(AjaxRequestTarget target, Form form) {
                        target.addComponent(feedback);
                        target.addComponent(myPage.getMyDataView());
                        window.close(target);
                }
                
                @Override
                protected void onError(AjaxRequestTarget target, Form form) {
                        target.addComponent(feedback);
                }
            });
       }
}
}

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to