Enviornment:托管Bean没有得到部署与应用程序的其余部分
- IDE:Eclipse的3.7
- 服务器:Tomcat的7.0
- JSF 2.0
我是新来的JSF和最近开始有一个奇怪的问题,当我尝试部署一个应用程序。
出于某种原因,除了bean之外,所有东西都被部署。当我注意到无论我做了什么,我都无法从facelet访问新创建的bean。然后我注意到我也无法使用在旧bean中创建的新函数。
我做了一个小实验,我在登录豆把现有的setter方法,以及改变了它:
public void setName(String name) {
this.name = name;
}
到
public void setName(String name) {
this.name = "not what was typed";
}
但那是从bean检索到的值在下一页是我输入到登录表单中的值。
我想我的faces-config.xml和web.xml文件都设置正确。我搜索了这个问题,唯一发现的是在bean声明之前添加@ManagedBean和@SessionScope注释可能有助于旧版本的JSF,但它不起作用。
我已经尝试创建一个新的服务器,并重新创建项目,但这也没有帮助。下面是我与我的新项目获得(其拥有所有正确创建的相同文件的旧项目,文件和内容粘贴)的错误:
An Error Occurred:
javax.el.PropertyNotFoundException: /login.xhtml at line 21 and column 42 value="#{loginBean.name}": Property 'name' not found on type com.tutorial.LoginBean
Caused by:
javax.el.PropertyNotFoundException - /login.xhtml at line 21 and column 42 value="#{loginBean.name}": Property 'name' not found on type com.tutorial.LoginBean
这里是登录豆:
/**
* LoginBean.java
*
*/
package com.tutorial;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
@ManagedBean(name="loginBean")
@SessionScoped
public class LoginBean {
private String name;
private String password;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public void savePerson(ActionEvent actionEvent) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Welcome "
+ name + " " + password + "!"));
}
}
在这里,我们有从login.xhtml一个片段,它使用变量LoginBean
<ui:define name="sideBar">
<p:accordionPanel multiple="true" activeIndex="0,1">
<p:tab title="Login" id="loginTab">
<h:form>
<h:panelGrid columns="1" style="width: 179px;" class="noBorder">
<h:outputLabel for="username" value="Username"></h:outputLabel>
<p:message for="username" id="msgUsername" />
<h:inputText id="username" value="#{loginBean.name}"
required="true" label="Username"></h:inputText>
<h:outputLabel for="password" value="Password"></h:outputLabel>
<p:message for="password" id="msgPassword" />
<h:inputSecret id="password" value="#{loginBean.password}"
required="true" label="Password">
</h:inputSecret>
<h:commandButton action="login"></h:commandButton>
</h:panelGrid>
</h:form>
</p:tab>
<p:tab title="Information">
Blah blah blah.
</p:tab>
</p:accordionPanel>
</ui:define>
任何人都知道问题是什么?
对不起,这篇冗长的文章。
你能提供你的'faces-config.xml'和'web.xml'吗? – 2012-01-17 11:53:51