wood burning stoves 2.0*
The moose likes JSF and the fly likes a JSF configure question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "a JSF configure question" Watch "a JSF configure question" New topic
Author

a JSF configure question

willow david
Greenhorn

Joined: Jul 26, 2005
Posts: 3
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>
--------------------------------------------------------------------

but when i deploy my application in Tomcat 5.0, i get such exception report: "javax.servlet.ServletException: javax.servlet.jsp.JspException: javax.faces.FacesException:
javax.faces.el.EvaluationException: Expression Error: Named Object: 'applicationScope' not found"

"applicatoinScope" is the implicit variable in JSF expression language, i don't know what is wrong? who can help me?
[ July 27, 2005: Message edited by: willow david ]
willow david
Greenhorn

Joined: Jul 26, 2005
Posts: 3
i have find the answer, it is the jsf-api and jsf-impl.jar version must be 1_1_01. but i got new problem, 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?
[ July 27, 2005: Message edited by: willow david ]
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Try removing "applicationScope." from your binding key.


A good workman is known by his tools.
willow david
Greenhorn

Joined: Jul 26, 2005
Posts: 3
i follow you advices, and removing "applicationScope." but the the code in login method of nameBean
------------------------------------------------------------------

TestBean testBean = (TestBean) application.createValueBinding(
"#{applicationScope.testBean}").getValue(context);

-----------------------------------------------------------------
still retutn null, and the testBean property of NameBean still is null, so the testBean property of NameBean don't be initialized as the defination in faces-config.xml
----------------------------------------------------------------
..............
<managed-property>
<property-name>testBean</property-name>
<property-class>demo.TestBean</property-class>
<value>#{testBean}</value>
<managed-property>
----------------------------------------------------------------
after the try when i didn't not use referenced-bean, but use the managed-bean instead. everything is ok,

This is a quote from the specification:

The �referenced-bean� element represents at design time the promise
that a Java object of the specified type will exist at runtime in some scope, under the specified key. This can be used by design time tools to construct user interface dialogs based on the properties of the specified class. The presence or absence of a referenced bean element has no impact on the JavaServer Faces runtime environment inside a web application.

but i still have some question:
1. why should I use #{testBean} in faces-config.xml, what is the wrong of #{applicationScope.testBean} and when i can use the #{applicationScope.testBean} in the code of login method, -----------------------------------------------------------
TestBean testBean = (TestBean) application.createValueBinding(
"#{applicationScope.testBean}").getValue(context);
---------------------------------------------------------
that is ok:

[ July 27, 2005: Message edited by: willow david ]
[ July 27, 2005: Message edited by: willow david ]
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Are you also registering TestBean as a managed-bean and not just a managed-property?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: a JSF configure question
 
Similar Threads
How do I preload bean for editing?
Integration problems using h:selectOneMenu
Obtaining an instance of a Managed Bean declared with Application Level Scope
how to over come conversion error
Issues with facelets and saveState?