You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by vov <vo...@mail.ru> on 2012/03/19 13:16:43 UTC
ModalWindow and Serialization
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?
--
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-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: ModalWindow and Serialization
Posted by vov <vo...@mail.ru>.
As I understand - the correct way is change usage PageCreator to setContent:)
Thank you very much for all your answers!!!
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/ModalWindow-and-Serialization-tp4484547p4484858.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: ModalWindow and Serialization
Posted by Martin Grigorov <mg...@apache.org>.
On Mon, Mar 19, 2012 at 3:31 PM, vov <vo...@mail.ru> wrote:
> 1) to as simple asgetSession().getAttribute(key) -
> getSession().getAttribute(key)
>
> It is not in the topic but:
> What it different between your proposal and
> getApplication().getSessionStore().setAttribute(requst, key, value);
mine calls ISessionStore#setAttribute() if the session is bound. If it
is temporary then it keeps the attribute in a temporary map.
>
> Maybe it's stupid question - how to remove object from session if you use
> getSession().getAttribute(key) ?
org.apache.wicket.Session#removeAttribute
but it is protected ... You will need to override it to make it public.
there is this comment in Wicket code :
// TODO WICKET-NG made public for page manager, used to be protected,
see if there is a way to
// revert
public final Serializable getAttribute(final String name)
so set and get are public but remove is not ...
We will improve this for Wicket 6!
>
> 2) Of course - ModalWindow.setContent(aPanel) will solve the problem. But
> in case if I have several modal windows on the one page - it's no good for
> performance. But I'm not sure about setting of the content on the fly
This will work. We do this in our app. There is one modal window which
content is dynamically loaded depending on the clicked link.
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/ModalWindow-and-Serialization-tp4484547p4484792.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: ModalWindow and Serialization
Posted by vov <vo...@mail.ru>.
1) to as simple asgetSession().getAttribute(key) -
getSession().getAttribute(key)
It is not in the topic but:
What it different between your proposal and
getApplication().getSessionStore().setAttribute(requst, key, value);
Maybe it's stupid question - how to remove object from session if you use
getSession().getAttribute(key) ?
2) Of course - ModalWindow.setContent(aPanel) will solve the problem. But
in case if I have several modal windows on the one page - it's no good for
performance. But I'm not sure about setting of the content on the fly
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/ModalWindow-and-Serialization-tp4484547p4484792.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: ModalWindow and Serialization
Posted by Martin Grigorov <mg...@apache.org>.
On Mon, Mar 19, 2012 at 3:03 PM, vov <vo...@mail.ru> wrote:
> Thanks for your answer,
> of course session is not so simple as local variable - but it one of the
> solution
as simple as getSession().setAttribute(key, value) -
getSession().getAttribute(key)
>
> Maybe in next releases of wicket someone will come up with a simpler
> solution
the solution is already there - ModalWindow.setContent(aPanel)
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/ModalWindow-and-Serialization-tp4484547p4484708.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: ModalWindow and Serialization
Posted by vov <vo...@mail.ru>.
Thanks for your answer,
of course session is not so simple as local variable - but it one of the
solution
Maybe in next releases of wicket someone will come up with a simpler
solution
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/ModalWindow-and-Serialization-tp4484547p4484708.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: ModalWindow and Serialization
Posted by Martin Grigorov <mg...@apache.org>.
Hi,
On Mon, Mar 19, 2012 at 2:16 PM, vov <vo...@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-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org