Hi,

On Mon, Mar 19, 2012 at 2:16 PM, vov <vov...@mail.ru> wrote:
> Hi All,
> I have a lot of work with ModalWindows in my project and want to use objects
> which created on the base page and are changed in the modal windows.
> I found that ModalWindow was changed in wicket 1.5 and want to ask about
> solution.
> Please see short example:
> // Base Page
> public class MyPage extends WebPage
> {
>  public MyPage()
>  {
>    final ModalWindow window = new ModalWindow("window");
>    add(new AjaxLink<Void>("link")
>    {
>      @Override
>      public void onClick(AjaxRequestTarget target)
>      {
>        final CustomObject object = new CustomObject();
>        window.setPageCreator(new ModalWindow.PageCreator()
>        {
>          @Override
>          public Page createPage()
>          {
>            return new MyModalWindow(object, window);
>          }
>        });
>        window.setWindowClosedCallback(new
> ModalWindow.WindowClosedCallback()
>        {
>          @Override
>          public void onClose(AjaxRequestTarget target)
>          {
>            if (object.isValue())
>            {
>              // This code is never executed {1} in wicket 1.5. But it
> worked in wicket 1.4
>            }
>          }
>        });
>      }
>    });
>  }
> }
>
> // Modal Window
> public class MyModalWindow extends WebPage
> {
>  public MyModalWindow(final CustomObject object, final ModalWindow window)
>  {
>    add(new AjaxLink<Void>("link")
>    {
>      @Override
>      public void onClick(AjaxRequestTarget target)
>      {
>        object.setValue(true);
>        window.close(target);
>      }
>    });
>  }
> }
>
> As I understand - the reason of this behavior is serialization of pages.
> I also know one solution - use PageReference(same with example here -
> http://www.wicket-library.com/wicket-examples/ajax/modal-window?0).
> But I want to ask - is there another solution? Use PageReference is not so
> flexible.
> For example I have a lot of modal windows which are opened from the panel.
> In this case I have to search my panel on the page. Moreover I can use one
> panel from different pages.
> Other problem - I don't want to use global variables on the Base Page - I
> want(ant in several cases I should) use local variables.
>
> Can anyone give advice - how to simplify usage of modal windows in such
> cases?

Not sure whether this goes against your rule to keep it "local"
(because it is not really local when you pass a final object to an
inner class) but I think
the safest way is to keep such objects in the session. You can share
objects (or even better models) between components in a page, but as
you already read about it this is not the case when you share between
pages.

So
- solution 1 - put the object in the session
- solution 2 - use ModalWindow with a Panel, instead of a page

>
> --
> View this message in context: 
> http://apache-wicket.1842946.n4.nabble.com/ModalWindow-and-Serialization-tp4484547p4484547.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to