简体   繁体   中英

Wicket model object instance is changing

I have created a Wicket model like this:

IModel<MyObject> myModel = new Model<MyObject>(new MyObject());

In order to debug a problem I created this snippet:

modalWindow.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {
            public void onClose(AjaxRequestTarget target) {
            System.out.println(myModel.getObject());
            }
        });

This print out a different object instance each time the onClose is invoked. Can someone please explain to me why this happens? Is this correct behavior? Shouldn't the myModel model object be the same instance every time?

Your model and the containing MyObject are serialized along with the page. Thus the identityHasCode changes, logically it's still the same object.

Thank you. By using a Panel instead, inside modalWindow, this is not happening anymore.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM