This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Child pages
  • Custom WebSession (Storing Objects In Session)
Skip to end of metadata
Go to start of metadata

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;
	}

	// if you use java >= 1.5 you can make use of covariant return types
	public static MySession get() {
		return (MySession)Session.get();
	}
}

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

public final class MyApplication extends WebApplication {
...
	@Override
	public final Session newSession(Request request, Response response) {
		return new MySession(request);
	}
...
}

In your WebPage you can get/set your object:

...

((MySession)Session.get()).setMyObject(myObject);
// or java >= 1.5:
MySession.get().setMyObject(myObject);

...
  • No labels