page navigation

Hi Toolkit folks!

I looked into the examples and they are clear enough to get me started.

Problem is: I’m building an application with public and private sections (need login). What I’m trying to do is a simple login box that is showed on every page.

Using JSP this would be easy by including a login box on every page, that checks the session status, but how do I do this with ITMILL?

(I found the setuser-function in application, but I don’t quite understand how to utilize that.)

I’m sorry if this is a stupid question. I found no relevant documentation about this use case.

Thanks,

Risto

Application.setUser/getUser is just a setter that stores any object. So it does not actually do anything. Still it is a handy way of storing a reference to your custom user object.

That said, you can simply put a Button (maybe with “link” style) to somewhere in your application and then add a listener handling the login to the button. If your application has a “top-level” layout, it would be a natural place to put your button.

The login listener could then just do something like:


if (getApplication().getUser() == null) {
   Window loginWindow = new Window("Login");
   TextField name = new TextField("Name");
   TextField password = new TextField("Password");
   password.setSecret(true);
   Button b = new Button("Login", Button.ClickListener() {
         if ("John".equals(""+name) && "secret".equals(""+password)) {
               getApplication().setUser(""+name);
               loginButton.setCaption("logout");
         }
         getApplication().removeWindow(loginWindow);
   });
   loginWindow.addComponent(name);
   loginWindow.addComponent(password);
   loginWindow.addComponent(b);
   getApplication().addWindow(loginWindow);
} else {
   loginButton.setCaption("login");
   getApplication().setUser(null);
}

(The above code snipper probably has ~ 5 bugs / line, as i did not check it, but I hope that you get the idea).