我正在使用JSF 2.1和Maven构建基于ICEmobile的Web应用程序。当我的jsf页面没有查找它的bean但我仍然可以构建和部署没有错误的项目时,我遇到了这个问题,我通过Eclipse中的运行配置部署项目:clean tomcat7:run-war
。即使我通过注释或applicationContext.xml声明bean,页面仍然没有正确调用bean。我可以在bean中获取字段的值,但无法调用该bean中的方法System.out.println("Pressed");
不向控制台提供输出。我猜它必须与我的配置有关,但我不知道在哪里查看。请给我一些提示。感谢
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:util="http://java.sun.com/jsf/composite/components"
xmlns:mobi="http://www.icesoft.com/icefaces/mobile/component"
xmlns:ice="http://www.icesoft.com/icefaces/component"
xmlns:icecore="http://www.icefaces.org/icefaces/core">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
<meta name="viewport"
content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<title>ICEfaces Mobile Showcase</title>
<mobi:deviceStylesheet media="screen" />
</h:head>
<h:body>
<mobi:pagePanel>
<f:facet name="body">
<h:form>
<mobi:commandButton value="#{buttonBean.buttonName}" buttonType="important" actionListener="#{buttonBean.buttonPress}">
<f:attribute name="buttonState" value="change"/>
</mobi:commandButton>
</h:form>
</f:facet>
</mobi:pagePanel>
</h:body>
</html>
The Bean:
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;
@ManagedBean(name = ButtonBean.BEAN_NAME)
@SessionScoped
public class ButtonBean implements Serializable {
private static final long serialVersionUID = 1L;
public static final String BEAN_NAME = "buttonBean";
private String buttonName = "0";
public String getButtonName() {
return buttonName;
}
public void setButtonName(String buttonName) {
this.buttonName = buttonName;
}
public void buttonPress(ActionEvent event){
System.out.println("Pressed");
String buttonState = (String)event.getComponent().getAttributes().get("buttonState");
if (buttonState.equals("change") && buttonName.equals("0")) buttonName = "1";
else if (buttonState.equals("change") && buttonName.equals("1")) buttonName = "0";
}
}
答案 0 :(得分:0)
我发现我的web.xml设置为2.5版。更改为3.0版。现在所有的作品