开发者

Init Variable with value from Session in ZK?Why Always get null value?

开发者 https://www.devze.com 2023-03-11 21:30 出处:网络
iam getting error when initilize variable with value is from session.. my program like this: public class OTPController extends GenericForwardComposer implements Initiator{

iam getting error when initilize variable with value is from session.. my program like this:

public class OTPController extends GenericForwardComposer implements Initiator{
    private String valueOTP;
    private Rusers user;
    public void doInit(Page arg0, Map arg1) throws Exception {
            user=(Rusers) arg1.get("user");
            System.out.println("user Id="+user);
    }

when i printout the value in init,the value is null..

if i take the session value like this:

    public void doInit(Page arg0, Map arg1) throws Exception {
            user=(Rusers) session.getAttribute("user");
            System.out.println("user Id="+user);
    }

the value is null too..

iam set the session like this:

session.setAttribute("user", user);

anybody can help me?iam very confuse,because if i hit the action after that null initialization and print out the result for example:

public void onClick$evaluate(Event event){
        String key=(String) session.getAttribute("key");
        if(valueOTP.equals(key)){ 
 开发者_如何学Python           System.out.println("user Id="+user);
            session.invalidate();
            session.setAttribute("user", user);
            execution.sendRedirect("./Welcome.zul");
        }else{
            System.out.println("OTP Failed");
            execution.sendRedirect("./Login.zul");
        }
    }

the value is show ,not null anymore..but if i init the variable,the value is null..anybody can help me?

thanks for your attention,and sorry for my bad english..


i got naswer fro my question,and i want to share maybe somebody got same problem with me,simply change how you get the session object,like this:

public void doInit(Page arg0, Map arg1) throws Exception {
            session=Executions.getCurrent().getSession();
            user=(user) session.getAttribute("user");
            System.out.println("user Id="+user);
    }

the value is not null anymore..this is the right way to get the session object..thanks for your attention..

0

精彩评论

暂无评论...
验证码 换一张
取 消