0

Help: Executions.sendRedirect() kills Session with ZK 7.0.2

asked 2014-07-08 11:48:13 +0800

Neus gravatar image Neus
1415 14

Hi, I'm updating my application from ZK 6.0.3 to ZK 7.0.2. I have a Login page. When user logs in, a Session attribute is set, page is redirected to the menu using Executions.sendRedirect() and user is consulted from the Session attribute. Until now, with ZK 6.0.3 this works perfect. Now, with the new version, after redirecting to the menu the Session is changed (it has a different id than before redirecting) and the attributes that were saved in it are not longer there.

What has changed? What I need to do now to preserve the session?

delete flag offensive retag edit

Comments

do you still encounter this issue if you don't use custom theme? Because I cannot reproduce the issue you said.

hawk ( 2014-07-10 03:28:50 +0800 )edit

Yes, I'm still encountering the issue even with sapphire theme. There's someting in my application that kill my session when I log in. I will continue investigating it and if I encounter something I tell here.

Neus ( 2014-07-14 08:11:18 +0800 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2014-07-09 10:17:24 +0800

cyiannoulis gravatar image cyiannoulis
1201 10

updated 2014-07-09 10:19:47 +0800

You shouldn't have any problem regarding the session attributes. Here is a complete example tested with ZK 7.0.2

The Login page:

<?page title="Login" contentType="text/html;charset=UTF-8"?>
<zk>
<window apply="org.zkoss.bind.BindComposer" 
        viewModel="@id('vm') @init('snippets.login.LoginVM')" 
        border="none"  
        xmlns:n="native"
        style="overflow: auto;">

    <div align="center" style="margin-top: 10%">
        <vlayout>
            <textbox type="text" placeholder="Username" value="@bind(vm.username)" 
                    sclass="input-lg" />
            <textbox type="password" placeholder="Password" value="@bind(vm.password)" 
                    sclass="input-lg" />
            <hlayout>
                <div class="btn-group">
                    <button label="Login" sclass="btn btn-lg btn-success" width="50%" 
                            onClick="@command('login')" />
                    <button label="Quit" sclass="btn btn-lg btn-danger" width="50%" 
                            href="http://www.pixar.com" />
                </div>
            </hlayout>
        </vlayout>
    </div>
</window>
</zk>

The Login View Model:

import org.zkoss.bind.annotation.Command;
import org.zkoss.zk.ui.Executions;

public class LoginVM {

    private String username;
    private String password;

    @Command
    public void login() {
        Executions.getCurrent().getSession().setAttribute("username", this.username);
        Executions.getCurrent().getSession().setAttribute("password", this.password);
        Executions.sendRedirect("welcome.zul");
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}

The Welcome page:

<?page title="Login" contentType="text/html;charset=UTF-8"?>
<zk>
<window apply="org.zkoss.bind.BindComposer" 
        viewModel="@id('vm') @init('snippets.login.WelcomeVM')" 
        border="none"  
        xmlns:n="native"
        style="overflow: auto;">

    <div align="center" style="margin-top: 10%">
        <n:h1>Welcome back <label value="@load(vm.username)" style="font-size: 26pt"/></n:h1>
        Password:<label value="@load(vm.password)" />
    </div>
</window>
</zk>

And the Welcome view model:

import org.zkoss.zk.ui.Executions;

public class WelcomeVM {

    public String getUsername() {
        return (String) Executions.getCurrent().getSession().getAttribute("username");
    }

    public String getPassword() {
        return (String) Executions.getCurrent().getSession().getAttribute("password");
    }
}

Hope that helps

Costas

link publish delete flag offensive edit

Comments

I'm almost sure it only happens when I try to load custom themes made with ZK 7 ThemeRoller. And maybe because I'm having problems with it too (see http://forum.zkoss.org/question/93538/exception-when-loading-a-custom-zk-7-theme-made-with-theme-roller/)

Neus ( 2014-07-09 11:12:45 +0800 )edit

ah... this is something you should have mention :) I am also sure it has to do with your custom theme..

cyiannoulis ( 2014-07-09 12:29:42 +0800 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2014-07-08 11:48:13 +0800

Seen: 26 times

Last updated: Jul 09 '14

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More