i am developing a web application using Java server faces, i have some question :
i configure a managed bean in faces-fconfig.xml file as follow:
---------------------------------------------------------
<managed-bean>
<managed-bean-name>nameBean</managed-bean-name>
<managed-bean-class>demo.NameBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>testBean</property-name>
<property-class>demo.TestBean</property-class>
<value>#{applicationScope.testBean}</value>
</managed-property>
</managed-bean>
-------------------------------------------------------------
testBean is a property of the class NameBean, it is a client class demo.TestBean. in order to refereced the testBean objecet, i configure a referenced bean in faces-config.xml
as follow:
-----------------------------------------------------------
<referenced-bean> <referenced-bean-name>testBean</referenced-bean-name>
<referenced-bean-class>demo.TestBean</referenced-bean-class
</referenced-bean>
-------------------------------------------------------------
my NameBean's code is
------------------------------------------------------------------------
public class NameBean {
private String userName;
private TestBean testBean;
/**
* @return User Name
*/
public String getUserName() {
return userName;
}
/**
* @param User
* Name
*/
public void setUserName(String name) {
userName = name;
}
public String login() {
FacesContext context = FacesContext.getCurrentInstance();
Application application = context.getApplication();
TestBean testBean = (TestBean) application.createValueBinding(
"#{applicationScope.testBean}").getValue(context);
return "greeting";
}
public TestBean getTestBean() {
return testBean;
}
public void setTestBean(TestBean testBean) {
this.testBean = testBean;
}
}
--------------------------------------------------------------------
the TestBean code as follow:
-------------------------------------------------------------------
public class TestBean implements Serializable {
private String loginName = "willow";
public TestBean() {
}
public String getLoginName() {
return loginName;
}
public void setLoginName(String loginName) {
this.loginName = loginName;
}
}
---------------------------------------------------------------------
but when i excute in NameBean's login Method, i want to get the refrence of TestBean by follow code:
TestBean testBean = (TestBean) application.createValueBinding(
"#{applicationScope.testBean}").getValue(context);
but i got testBean is null, i have configure referenced bean in faces-config.xml file,
--------------------------------------
<referenced-bean> <referenced-bean-name>testBean</referenced-bean-name> <referenced-bean-class>demo.TestBean</referenced-bean-class
</referenced-bean>
-----------------------------------------
why testBean is null? what's the problem?
-
JSF Configure problem (2 messages)
- Posted by: David liu
- Posted on: July 27 2005 02:28 EDT
Threaded Messages (2)
- JSF Configure problem by Duncan Mills on July 28 2005 17:33 EDT
- JSF Configure problem by Chris Schalk on July 28 2005 23:10 EDT
-
JSF Configure problem[ Go to top ]
- Posted by: Duncan Mills
- Posted on: July 28 2005 17:33 EDT
- in response to David liu
<referenced-bean> indicates that the object will be created externally from JSF and is not managed by JSF. As such getting a value binding to it would not force an instance of demo.TestBean to get created.
If you change that to be a <managed-bean> then it will be implictly be created when any EL referrs to it. -
JSF Configure problem[ Go to top ]
- Posted by: Chris Schalk
- Posted on: July 28 2005 23:10 EDT
- in response to Duncan Mills
Also remember that when you set up dependencies between managed beans which is what you'll have here, they can't be interdependent on each other. Cyclical dependencies are not supported by JSF's managed bean facility.