lol. Next time ask the community earlier. I always try to solve my
problems alone.
Sometimes it helps to build a quickstart and focus to the problem. But
if i realy don't have an idea
and google is not helping to - then i ask here. Normally you get help in
short time.
Btw: Thanks to all helping others out of their problems.
Cheers
Per
Am 09.02.2012 20:00, schrieb René Bernhardsgrütter:
Hi Per, thank you very much for your answers.
Yes, that was it. I added WiaSession.get().bind(); to my LoginPanel
and now it works as it should :-)
Every time when the LoginPanel is showed, the session will be binded.
Phu, I was trying to fix that over three days ^^
Regards,
René
On 02/09/2012 06:53 PM, Per Newgro wrote:
And maybe this javadoc helps
Session#bind()
/**
* Force binding this session to the application's {@link
ISessionStore session store} if not
* already done so.
* <p>
* A Wicket application can operate in a session-less mode as
long as stateless pages are used.
* Session objects will be then created for each request, but
they will only live for that
* request. You can recognize temporary sessions by calling
{@link #isTemporary()} which
* basically checks whether the session's id is null. Hence,
temporary sessions have no session
* id.
* </p>
* <p>
* By calling this method, the session will be bound (made
not-temporary) if it was not bound
* yet. It is useful for cases where you want to be absolutely
sure this session object will be
* available in next requests. If the session was already bound (
* {@link ISessionStore#lookup(Request) returns a session}), this
call will be a noop.
* </p>
*/
Am 09.02.2012 18:45, schrieb Per Newgro:
If i understood your usecase correctly you're app is still stateless
if you logged in.
Afaik no session is created for stateless pages. So after you've
logged in the session
is away for your next page. And then the user is away to. You could
debug it by print the
hashcode of getSession() in the page.
Cheers
Per
Hello,
I have a strange problem with StatelessForms in combination with
login in:
On my MainPage are two stateless forms. One for registration and
one for the
login (registration isn't implemented yet). When I try to log in,
Wicket
creates a new User() and saves it in the Session (I made this like
it's
explained in Wicket in Action). A System.out.print("user created")
in the
constructor of User confirms that. Everything seems to be ok. But
when the
main page reloads, I am still logged out.
And: When I change from StatelessForm to Form, everything works
perfectly.
Something else might be important: When I request a page that requries
authorization and I'm not logged in, i'm being redirected to
/login. There
is the same LoginPanel (with StatelessForm) as on the main page -
and the
login works! But when I directly open /login it's the same as on
the main
page and I can't login.
I also noticed that the login works (with StatelessForm) when I
open a page
that requires authorization, then press the back button (back to
main page)
and there try to log in.
The question is now, what am I doing worng? I can't find the
problem in my
code, I have been trying a lot to find out what's worng but
everything seems
to be correct. I couldn't find anything in the mailing list / on
the web, I
searched a lot.
At the end I attached code from LoginPanel.java, WiaSession.java and
WicketApplication.java.
Thank you very much for your help!
(And sorry if there are one or two missspelled words - I don't
speak english
natively.)
René
LoginPanel.java:
public class LoginPanel extends Panel {
public LoginPanel(String id) {
super(id);
add(new LoginForm("login"));
}
private class LoginForm extends StatelessForm {
private String username;
private String password;
public LoginForm(String id) {
super(id);
setModel(new CompoundPropertyModel(this));
add(new TextField("username"));
add(new PasswordTextField("password"));
}
@Override
public final void onSubmit() {
if (tryToLogIn()) {
if (!continueToOriginalDestination()) {
setResponsePage(getApplication().getHomePage());
}
}
}
private boolean tryToLogIn() {
if (username != null&& password != null) {
User user = Database.findUser(username);
if (user != null) {
if (user.comparePasswords(password)) {
WiaSession.get().setUser(user);
return true;
}
}
}
return false;
}
}
}
WiaSession.java:
public final class WiaSession extends WebSession {
private User user;
public WiaSession(Request request) {
super(request);
}
public static WiaSession get() {
return (WiaSession) Session.get();
}
public static boolean isLoggedIn() {
return WiaSession.get().isAuthenticated();
}
public boolean isAuthenticated() {
return (user != null);
}
public final synchronized User getUser() {
return user;
}
public final synchronized void setUser(User user) {
this.user = user;
}
}
WicketApplication.java, newSession overwritten:
@Override
public final Session newSession(Request request, Response
response) {
return new WiaSession(request);
}
--
View this message in context:
http://apache-wicket.1842946.n4.nabble.com/StatelessForm-Cannot-login-tp4373476p4373476.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org