Anyhow I seem to be having a problem getting it working...here's what I've got so far.
Here's my session class:
public class UserSession extends WebSession
{
private User user;
public UserSession(Application application)
{
super(application);
}
public User getUser()
{
return this.user;
}
public void setUser(User user)
{
this.user = user;
}
public boolean authenticate()
{
if (this.getUser() == null)
return false;
else
return true;
}
}
I modified my EditProductApp class to include the overridden method:
public ISessionFactory getSessionFactory()
{
return new ISessionFactory()
{
public Session newSession()
{
return new UserSession(EditProductApp.this );
}
};
}
In the page, I check to see if the user exists:
UserSession us = new UserSession(EditProductApp.get());
if (!us.authenticate())
setResponsePage(new Login());
...if not, I send them back to the login page...the problem is; they *always* get redirected...so to continue w/ the login page:
the login app class overrides the getSessionFactory() method:
public ISessionFactory getSessionFactory()
{
return new ISessionFactory()
{
public Session newSession()
{
return new UserSession(LoginApp.this);
}
};
}
the login page submit action looks like this:
//event handler
public void onSubmit()
{
//authenticate user
User formUser = (User)getModelObject();
User dbUser = UserProxy.getAuthUser(formUser.getUsername(), formUser.getPassword());
UserSession us = new UserSession(LoginApp.get());
us.setUser(dbUser);
if (dbUser == null)
{
setResponsePage(new Login()); //login failed
}
else if (dbUser.isActive())
{
if (dbUser.getUserGroup ().getAccessLevel() == 1)
setResponsePage(new Home());
else
setResponsePage(new ProductCatalog());
}
else
{
setResponsePage(new InactiveAccount());
}
}
So, I login (that part works fine) and then go to the EditProduct page and get redirected to the Login page...the value was apparently *not* stored in session.
What am I missing?
Thanks!!
On 3/16/06, Igor Vaynberg <[EMAIL PROTECTED]> wrote:
we do not provide that get/setObject() method because we want to encourage type safety.
furthermore the session is also used to store application logic, like logic related to authentication/authorization or anything else youd like. it is not a simple Map<String,Object> like http session, it can be much much more.
-IgorOn 3/16/06, Vincent Jenks < [EMAIL PROTECTED]> wrote:Just as an observation, this seems a bit cumbersome to simply add/access/remove objects from the HttpSession (but that's just my opinion.)
It make sense, it just seems like a lot of work to tap into session values.
I suppose if I had a single getter/setter that used an Object parameter I could make something that behaved more like the HttpSession when used in JSP/Servlets...but then I've got to override getSessionFactory() in every Application class I want to use it in.
Anyhow, thanks for your help!On 3/16/06, Igor Vaynberg < [EMAIL PROTECTED]> wrote:yep.
-IgorOn 3/16/06, Vincent Jenks < [EMAIL PROTECTED]> wrote:MySessionObject being a class you created subclassing WebSession?On 3/16/06, Jonathan Cone <[EMAIL PROTECTED] > wrote:Hey Vincent,What I would do is override getSessionFactory in your application class, something like this:@Override
protected ISessionFactory getSessionFactory() {
return new ISessionFactory() {public Session newSession() {
return new MySessionObject(YourApplicationClass.this);
}
};
}Now MySessionObject is a subclass of WebSession (You'll want to look at this class). In your pages you would do something like:((MySessionObject)getSession()).getUsername();Make sense?----- Original Message -----From: Vincent JenksSent: Thursday, March 16, 2006 5:01 PMSubject: [Wicket-user] objects in sessionIf objects used in a page are stored in a session, how do I access those objects when I redirect to a new page? Say I have public users who login and I want to display their name on pages and keep their user info in-session...on each page, how would I call those values?
Thanks!
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.385 / Virus Database: 268.2.3/281 - Release Date: 3/14/2006