我遇到了我的会话作用域bean的奇怪行为。我用以下的进口和注释,使其sessionscoped:@SessionScoped bean @ViewScoped行为
编辑:更多的代码
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;
@Named
@SessionScoped
public class DetailsBean implements Serializable {
private LinkedHashMap<String, String> folder;
@Inject
private ApplicationBean appBean;
@Inject
private UserBean userBean;
@PostConstruct
public void resolveID() {
this.folder = new LinkedHashMap<String, String>();
for (LinkedHashMap<String, String> tempfolder : appBean.getRepositoryContent()) {
if (tempfolder.get("text:nodeid").equals(URLid)) {
this.folder = tempfolder;
}
}
}
JSF页面的代码片段:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:rich="http://richfaces.org/rich">
<f:metadata>
<f:viewParam name="id" value="#{detailsBean.URLid}" required="true" requiredMessage="You must provide an Object Id"/>
<f:event type="preRenderView" listener="#{detailsBean.resolveID}" />
</f:metadata>
<h:head>
<title>Dataset #{detailsBean.name}</title>
</h:head>
<h:body>
<h:form>
<h:panelGrid columns="2" columnClasses="fixed-column">
Name <h:inputText value="#{detailsBean.name}"
id="name" required="true"
requiredMessage="name required"/>
<rich:message for="name" ajaxRendered="true"/>
</h:panelGrid>
</h:body>
</h:form>
</html>
现在,当我点击一个链接在我的JSF页面这样的一个DetailsBean被实例化。当我点击另一个具有不同内容的链接时,使用相同的bean,因为我仍然在同一个Session中。现在奇怪的是,即使我创建了2个不同的浏览器标签,即使在刷新页面后,它们也显示不同的内容。同一个bean实例如何显示不同的内容?我通常认为只有一个@ViewScoped bean可以实现这一点?不要误会我我想让他们展示不同的内容,所以@ViewScoped将是在这里使用的正确决定,但我只是想知道这是如何可能的...
EDIT2:当我使用javax.faces.ViewScoped ,上面的代码不工作了(我得到java.io.NotSerializableException因为LinkedHashMap中的那么)
它不应该是可能的,但如果你有一些逻辑事情在你的支持者,你是不知道的,那么有可能。请发布更多代码。 – Catfish
好吧我编辑。 jsf页面上的内容使用文件夹映射并从中获取字符串。 – nico1510
你能发布使用这个支持bean的视图代码片段吗? – Catfish