简体   繁体   中英

new bean for every wicket session

I was creating my first application using Apache wicket and am stuck on a problem. After the user logs in through the authentication method I have a new session which is created for that user. Now if I wanted to have data stored for just that user how would I use bean to implement that?

At the moment i created an interface and a class with get and set methods for the variables i wanted stored and created a bean such as <bean id="springApplicationContext" class="com..util.SpringApplicationContext"/> but what happens is the data gets overwritten but when i change the scope to "session" everyone has the same data in the bean still.

Thanks

The correct way is to use Session scoped Spring bean. There must be some error in your config if the data is visible to all users. Using Spring has nothing to do with Wicket though!

Alternative approach is to store your data in Wicket's Session class. Override MyApplication#newSession() method and return MySession class. The instance of MySession will be stored as an attribute in the HTTP session by Wicket. You can put any member fields inside MySession, eg;

public class MySession extends WebSession {
  ...
  private MyBean myBean; 
  // setter and getter
  ... 
}

Then in your Wicket code use it with: MySession.get().getMyBean().setSome(thing);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM