首先從Model
其實JavaBean只是一個特別的Java類而已
package net
public class UserInfo {
private String userName;
private String password;
public String getUserName(){
return userName;
}
public String getPassword(){
return password;
}
public void setUserName(String userName){
this
}
public void setPassword(String password){
this
}
//如果一個類中無構造函數
//因此
public UserInfo(){
}
}
需注意其中的格式要求
做過Model
再來解釋JSF中的MBean
最後是MBean的配置
<managed
<description>demo of config</description>
<display
<managed
<managed
<managed
</managed
對其中的managed
managed
managed
managed
下面再對manage
Name Scope
Application 整個應用
Session 整個對話
Request 整個請求
None 需要時
大家知道
◆經過測試證明
UserInfo ui = (serInfo)fc
◆對session級別的MBean
FacesContext fc = FacesContext
UserInfo ub = (UserInfo)fc
當然
◆對request級別的MBean
FacesContext fc = FacesContext
HttpServletRequest request = (HttpServletRequest)fc
UserInfo ui = (UserInfo)request
◆至於none類型的MBean
當然
FacesContext context = FacesContext
ValueBinding binding = context
UserBean user = (UserBean) binding
也可用如下的代碼直接得到MBean的一個屬性
FacesContext context = FacesContext
ValueBinding binding = context
String name = (String) binding
From:http://tw.wingwit.com/Article/program/Java/hx/201311/25866.html