Am using JSF 1.2 . I have a servlet. When this servlet is hit, am getting the data from request parameters, in doPost, and I need to set it in bean so that I can show it on xhtml page.
My code is like below.
userId= request.getParameter("userID");
MyBean myBean = new MyBean();
myBean.initialize(userId);
In initialize method of myBean am setting userId value into a globalVariable.
In my logs in bean, globalVariable value is getting printed. But its not getting displayed on xhtml page.
Am redirecting to xhtml page in doPost method like below,
RequestDispatcher dispatcher = request.getRequestDispatcher("/jsp/html/index.jsf");
dispatcher.forward(request, response);
In index.xhtml page, I have
<h:outputText value="#{myBean.globalVariable}"></h:outputText>
In my phaselistener am not doing any thing much. I just have beforPhase method.
Why am I not able to print the value in jsf page but able to print the value in log in bean?
Before forwarding, you need to put the bean in the scope, exactly there where JSF expects it.
If it’s a request scoped bean, use
HttpServletRequest#setAttribute().