• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

a JSF configure question

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try removing "applicationScope." from your binding key.
 
willow david
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you also registering TestBean as a managed-bean and not just a managed-property?
 
reply
    Bookmark Topic Watch Topic
  • New Topic