Custom WebSession (Storing Objects In Session) has been created by Will Hoover (Feb 13, 2008).

Content:

Extend WebSession and add your custom getters/setters:

public final class MySession extends WebSession {

	private Object myObject;

	public PerManSession(Request request) {
		super(request);
	}

	public final Object getMyObject() {
		return myObject;
	}

	public final void setMyObject(Object myObject) {
		this.myObject = myObject;
	}

}

In your WebApplication you need to override the "newSession" method and return your session instance:

public final class MyApplication extends WebApplication {
...
    @Override
    public final WebSession newSession() {
        return new MySession();
    }
...
}

In your WebPage you can get/set your object:

...

((MySession)Session.get()).setMyObject(myObject);

...

Reply via email to