You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Flavius <fl...@silverlion.com> on 2010/03/29 16:23:45 UTC

Passing / Persisting an object without PageParameters

 
I have a list page and a detail page.  The
list is the results of a search and I put
this in a listview.  The user can then click
each item to view it in the detail.

What I'm doing now is passing the result object
to the detail page so they can continue to 
navigate (next >) the results without having
to go back to the list.  Also, when they return
to the list, it should have the same results they
had (preferrably without requerying the database).

I now want to make the detail page bookmarkable.
So I can pass a string value along that identifies
the detail record to retrieve, but I'm in a quandry
as to how to handle the result object.

I need to put this someplace where the pages can see
it and all I can think of is the session.  I'm 
reluctant to put this on the session because it
will be > 1k in size and possibly up to 3k.  That's
a big object to put on the session, especially in 
a clustered environment.

Does anybody have any suggestions as to how to get
the bookmarkable detail page and still have a ref
to this result object?


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


Re: Passing / Persisting an object without PageParameters

Posted by James Carman <jc...@carmanconsulting.com>.
Well, what I have done in this situation is I use a "breadcrumb":

public class Breadcrumb implements Serializable
{
    private final PageReference destination;

    public Breadcrumb()
    {
        this.destination = PageReference.forRequestedPage();
    }

    public Link createCancelLink(String id)
    {
        return new CancelLink(id);
    }

    private class CancelLink extends Link
    {
        private static final long serialVersionUID = 1L;

        public CancelLink(String id)
        {
            super(id);
        }

        public void onClick()
        {
            redirectToDestination();
        }
    }

    public void redirectToDestination()
    {
        RequestCycle.get().setResponsePage(destination.getPage());
        RequestCycle.get().setRedirect(true);
    }

    public Page getDestinationPage()
    {
        return destination.getPage();
    }
}

public class PageReference<T extends Page> implements Serializable
{
//**********************************************************************************************************************
// Fields
//**********************************************************************************************************************

    private static final long serialVersionUID = 1L;

    private final String pageMapName;
    private final int number;
    private final int version;

    public static <T extends Page> PageReference<T> forPage(T page)
    {
        page.setStatelessHint(false);
        return new PageReference<T>(page.getPageMapName(),
page.getNumericId(), page.getCurrentVersionNumber());
    }

    public static PageReference<? extends Page> forRequestedPage()
    {
        final IRequestTarget target = RequestCycle.get().getRequestTarget();
        if(target instanceof IPageRequestTarget)
        {
            return forPage(((IPageRequestTarget)target).getPage());
        }
        throw new WicketRuntimeException("Unable to determine calling
page.");
    }

    private PageReference(String pageMapName, int number, int version)
    {
        this.pageMapName = pageMapName;
        this.number = number;
        this.version = version;
    }

    @Override
    public boolean equals(Object o)
    {
        if (this == o)
        {
            return true;
        }
        if (o == null || getClass() != o.getClass())
        {
            return false;
        }

        PageReference that = (PageReference) o;

        if (number != that.number)
        {
            return false;
        }
        if (version != that.version)
        {
            return false;
        }
        if (!pageMapName.equals(that.pageMapName))
        {
            return false;
        }

        return true;
    }

    @Override
    public int hashCode()
    {
        int result = pageMapName.hashCode();
        result = 31 * result + number;
        result = 31 * result + version;
        return result;
    }

    @SuppressWarnings("unchecked")
    public T getPage()
    {
        return (T) Session.get().getPage(pageMapName,
Integer.toString(number), version);
    }
}

The breadcrumb allows you to go back to the exact page where you came from.
I use it along with a page superclass called "LoopPage" and a link class
called "LoopLink":

public class LoopPage extends WebPage
{
    protected final Breadcrumb breadcrumb;

    public LoopPage()
    {
        this.breadcrumb = new Breadcrumb();
    }

    protected void redirectToDestination()
    {
        breadcrumb.redirectToDestination();
    }

    protected Page getDestinationPage()
    {
        return breadcrumb.getDestinationPage();
    }
}

public abstract class LoopLink extends SubmitLink
{
    public LoopLink(String id)
    {
        super(id);
        setDefaultFormProcessing(false);
    }

    protected abstract Page getLoopPage();

    @Override
    public final void onSubmit()
    {
        setResponsePage(getLoopPage());
        setRedirect(true);
    }
}

On Mon, Mar 29, 2010 at 10:23 AM, Flavius <fl...@silverlion.com> wrote:

>
> I have a list page and a detail page.  The
> list is the results of a search and I put
> this in a listview.  The user can then click
> each item to view it in the detail.
>
> What I'm doing now is passing the result object
> to the detail page so they can continue to
> navigate (next >) the results without having
> to go back to the list.  Also, when they return
> to the list, it should have the same results they
> had (preferrably without requerying the database).
>
> I now want to make the detail page bookmarkable.
> So I can pass a string value along that identifies
> the detail record to retrieve, but I'm in a quandry
> as to how to handle the result object.
>
> I need to put this someplace where the pages can see
> it and all I can think of is the session.  I'm
> reluctant to put this on the session because it
> will be > 1k in size and possibly up to 3k.  That's
> a big object to put on the session, especially in
> a clustered environment.
>
> Does anybody have any suggestions as to how to get
> the bookmarkable detail page and still have a ref
> to this result object?
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>