answered
2014-07-09 10:17:24 +0800
cyiannoulis 1201 ● 10 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
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 )editYes, 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