JSF 1.2 : Not able to retrieve bean values in xhtml page

巧了我就是萌 提交于 2019-12-11 12:45:07

问题


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?


回答1:


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().

request.setAttribute("myBean", myBean);


来源:https://stackoverflow.com/questions/11578940/jsf-1-2-not-able-to-retrieve-bean-values-in-xhtml-page

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!