?
1.????
通過
backing bean
對頁面的值進行綁定
?
JSF
封裝的
HTML
控件都有一個
binding
的屬性,通過該屬性可以在后臺對該控件取值賦值。
?
<
body
>
???????
<
f:view
>
???????
???????
<
h:form
>
???????
???????
???????
<
h:inputText
binding
=
"#{loginBean.txtUser}"></h:inputText>
???????
???????
???????
<
h:commandButton
actionListener
=
"#{loginBean.txtListener}"value="enter"></h:commandButton>
???????
???????
</
h:form
>
???????
</
f:view
>
</
body
>
?
?
???????
private
UIInput
txtUser
;
???????
public
UIInput getTxtUser() {
???????
???????
return
txtUser
;
??????? }
?
???????
public
void
setTxtUser(UIInput txtUser) {
???????
???????
this
.
txtUser
= txtUser;
??????? }???????
???????
???????
public
void
txtListener(ActionEvent e){
???????
???????
txtUser
.setValue(
"11111"
);
???????
??????? System.
out
.println(
txtUser
.getValue().toString());
??????? }
?
2.????
在一個
bean
中調用其它
bean
????????
????????
??????? FacesContext context = FacesContext.getCurrentInstance();
???????
???????
??????? ValueBinding binding = context.getApplication().createValueBinding(
???????
???????
???????
???????
???????
"#{uptBean}"
);
???????
???????
??????? uptBean bean = (uptBean) binding.getValue(context);
?
這段代碼就是用來調用
uptBean
。
CreateValueBinding
()方法中的參數,可以是
bean
,也可以
bean
中對應得數據。
?
?