Eclipse 托管bean未与应用程序的其余部分一起部署
环境:Eclipse 托管bean未与应用程序的其余部分一起部署,eclipse,jsf,tomcat7,myfaces,Eclipse,Jsf,Tomcat7,Myfaces,环境: IDE:Eclipse3.7 服务器:Tomcat7.0 JSF2.0 我是JSF新手,最近在尝试部署应用程序时遇到了一个奇怪的问题 出于某种原因,除了bean之外,所有的东西都被部署了。当我注意到无论我做什么,我都无法从facelet访问新创建的bean时,这就开始了。然后我注意到我也不能使用在旧bean中创建的新函数 我做了一个小实验,在登录bean中使用了一个现有的setter方法,并将其从: public void setName(String name) { thi
- IDE:Eclipse3.7
- 服务器:Tomcat7.0
- JSF2.0
public void setName(String name) {
this.name = name;
}
到
但是在下一页从bean中检索到的值是我在登录表单中键入的值
我认为我的faces-config.xml和web.xml文件都设置正确。我在谷歌上搜索了这个问题,发现的唯一一件事是在bean声明之前添加@ManagedBean和@SessionScope注释可能有助于JSF的旧版本,但它不起作用
我曾尝试创建一个新服务器,并重新创建项目,但也没有帮助。以下是我在新项目中遇到的错误(该项目具有与旧项目相同的所有文件、正确创建的文件以及粘贴的内容):
以下是登录bean:
/**
* 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>
废话废话。
有人知道问题出在哪里吗
抱歉,文章太长。您是否清理了所有现有的编译代码?好像有一些老班级在附近。使用eclipse时有时会发生这种情况
也可能是tomcat类路径与eclipse类路径不同。您能提供您的
faces config.xml
和web.xml
?这就是答案。为了让它工作,我必须清理项目,然后清理服务器,然后运行项目。如果我只清理其中一个,那么bean将无法正确部署。
/**
* 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 + "!"));
}
}
<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>