SessionScoped ManagedBean我在我的應用程序中配置一個過濾器,攔截所有的請求,它需要設定值命名爲userInfo
某個bean UserInfoBean
其被定義爲ManagedBean
,這是SessionScoped
。設置使用Servlet API的
當我試圖創建的UserInfoBean
一個實例,並將其設置與名稱userInfo
會話並試圖訪問JSF頁面上像#{userInfo.firstName}
,返回null
值。我的方法有什麼問題?
bean類是:
@ManagedBean (name="userInfo")
@SessionScoped
public class UserInfoBean {
private String firstName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public UserInfoBean(String firstName) {
this.firstName = firstName;
}
}
在濾波代碼爲:
public void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
....
HttpSession session = request.getSession();
session.setAttribute("userInfo", new UserInfoBean("Joe"));
....
}
的JSF代碼是:
<h:outputText value="#{userInfo.firstName}" />