1
正在使用JSF 1.2。我有一個servlet。當這個servlet被命中時,我正在從doPost的請求參數中獲取數據,並且我需要在bean中設置它,以便我可以在xhtml頁面上顯示它。JSF 1.2:無法在xhtml頁面中檢索bean值
我的代碼如下所示。
userId= request.getParameter("userID");
MyBean myBean = new MyBean();
myBean.initialize(userId);
在myBean的初始化方法中,將userId值設置爲globalVariable。
在我的bean日誌中,globalVariable值正在打印。但它沒有顯示在xhtml頁面上。
上午重定向到XHTML頁面中doPost方法如下圖所示,
RequestDispatcher dispatcher = request.getRequestDispatcher("/jsp/html/index.jsf");
dispatcher.forward(request, response);
在頁面的index.xhtml,我有
<h:outputText value="#{myBean.globalVariable}"></h:outputText>
在我的PhaseListener我沒有做任何事情了。我只是採用了beforPhase方法。
爲什麼我無法打印jsf頁面中的值,但能夠在登錄bean中打印值?
它像一個魅力工作。感謝BalusC。如果myBean是會話作用域? – 2012-07-20 12:37:22
通過'request.getSession()。setAttribute(「myBean」,myBean)'將其設置爲會話屬性。 – BalusC 2012-07-20 12:42:40