tags:

views:

58

answers:

1

I am giving a link to user to activate his account. Link is http://xyz.in/JSF_WEB_WFE/faces/index.jsp?confirmuser=jona&emailid=valid. I read the parameters in a Beans constructor and then making some decision like, activated / already activated. It works fine in local but while we deploy in web some times it works fine and some time not. what may be the problem. What can we do for better solution?

public AuthendicationBean() {
    try {
        HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();

        if (request.getParameter("confirmuser") != null && request.getParameter("emailid") != null) {
            int i = AccountManager.activationUser(request.getParameter("confirmuser"), request.getParameter("emailid"));
            if (i == 1) {
                activationmessage = "<b>" + request.getParameter("confirmuser") + "&nbsp;is Activated</b>";
                activerender = true;
                FacesContext.getCurrentInstance().addMessage("userForm", new FacesMessage(request.getParameter("confirmuser") + "\t is Activated" + i));
            } else if (i == 2) {
                activationmessage = "<b>" + request.getParameter("confirmuser") + "&nbsp;is Deactivated</b>";
                activerender = true;
                FacesContext.getCurrentInstance().addMessage("userForm", new FacesMessage(request.getParameter("confirmuser") + "\t is Deactivated"));
            } else {
                activationmessage = "<b>" + request.getParameter("confirmuser") + "&nbsp is   activated</b>";
                activerender = true;
                FacesContext.getCurrentInstance().addMessage("userForm", new FacesMessage(request.getParameter("confirmuser") + "\t is already Deactivated"));
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return "";
}
A: 

I got the solution. It works fine when I put the AuthendicationBean in requset scope. Previously it was in session scope that may be the problem.

Paul
I've found that very few things really belong in session scope. A bean holding the contents of a "shopping cart", yes, but page backing beans and anything related to authentication should be per-request, to avoid problems relating to use of the back button or multiple browser windows, or stale authentication information being used. (However, preserving bean state across postbacks is problematic when using request-scoped backing beans; Apache Tomahawk's `saveState` component helps a lot.)
Wyzard