I have a use case where several pages of a flow need to edit a
DTO. Changes to the DTO (which may be an existing JPA Entity, or a
not-yet-persisted one) are saved at the end of the flow (assuming the
user clicks "save").

The user is allowed to navigate back-and-forth among the pages, so the
obvious trick of passing the modified DTO to the next page via its
constructor won't work- the back button will lead to a page with a
potentially stale DTO.

I'm thinking of storing the DTO in the user's session as a detached
entity, and using a model like the following on the various pages:

public class SessionModel<T extends Serializable> implements IModel<T>
{
    protected String key;

    public SessionModel(String key)
    {
        this.key = key;
    }

    public SessionModel(String key, T object)
    {
        this.key = key;
        setObject(object);
    }

    public T getObject()
    {
        return (T) Session.get().getAttribute(key);
    }

    public void setObject(T object)
    {
        Session.get().setAttribute(key, object);
    }

    public void detach()
    {
        // no-op
    }
}

Does this seem like a reasonable approach? Is there an existing model
that I've overlooked that does this already? Is there a better way to
accomplish the multi-page flow without stuffing objects into the
session?

Thanks


--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/a-model-for-passing-data-between-pages-tp4542878p4542878.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to