I tried to subclass Wicket WebSession so that I could implement a basic authentication system. I followed the recommendations in the Wicket help library. When I try to execute the following in my WebPage, I get a ClassCastException:
((AppSession)Session.get()).setUid()
Here is the complete error:
java.lang.ClassCastException: org.apache.wicket.protocol.http.WebSession cannot be cast to com.example.webapp.AppSession
I searched the Internet for many hours and tried everything I could. I would really appreciate help. Also, please let me know if there is a better way to do this. I am really new to the gate.
Thanks.
AppSession.java
public final class AppSession extends WebSession { private Integer uid; public AppSession(Request request) { super(request); } public final Integer getUid() { return uid; } public final void setUid(Integer uid) { this.uid = uid; } public static AppSession get() { return (AppSession)Session.get(); } }
App.java
public class App extends WebApplication { public App() { super(); new AnnotatedMountScanner().scanPackage("com.example.webapp").mount(this); } @Override public Session newSession(Request request, Response response) { return new AppSession(request); } @Override public Class getHomePage() { return null; } }
source share