我在JSF工作,但是只要托管bean在请求范围内,我就无法从t:saveState获取属性值。
这是我的托管bean类:
@ManagedBean(name="demoBean")
@RequestScoped
public class DemoBean {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String submitButton() {
System.out.println("submitButton method");
return "nextPage";
}
}
index.xhtml页面在这里
<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:t="http://myfaces.apache.org/tomahawk">
<head>
</head>
<body>
<t:saveState value="#{demoBean.name}"></t:saveState>
<h:form id="demoForm">
<t:outputLabel value="Name:" style="font-weight:bold"></t:outputLabel>
<t:inputText value="#{demoBean.name}" id="txt"></t:inputText>
<t:commandButton value="Submit" action="#{demoBean.submitButton}"></t:commandButton>
</h:form>
</body>
</html>
NextPage.xhtml就在这里
<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:t="http://myfaces.apache.org/tomahawk">
<head>
<title>Insert title here</title>
</head>
<body>
<h:form>
<h:outputLabel value="I am here #{demoBean.name}"></h:outputLabel>
</h:form>
</body>
</html>
任何帮助都会有用
答案 0 :(得分:0)
我意识到这是一篇旧帖子,但你不必添加
<t:saveState value="#{demoBean.name}"></t:saveState>
到http://wiki.apache.org/myfaces/SaveState下的Nextpage.xhtml?