Jsf 具有相同ViewScope bean类的多个浏览器选项卡或窗口
使用Payara服务器4.1.2.174和mojarra 2.2.15 我有一个简单的命名Bean,其作用域为javax.faces.view.ViewScopedJsf 具有相同ViewScope bean类的多个浏览器选项卡或窗口,jsf,glassfish,jsf-2.2,mojarra,view-scope,Jsf,Glassfish,Jsf 2.2,Mojarra,View Scope,使用Payara服务器4.1.2.174和mojarra 2.2.15 我有一个简单的命名Bean,其作用域为javax.faces.view.ViewScoped import java.io.Serializable; import java.util.logging.Level; import java.util.logging.Logger; import javax.annotation.PostConstruct; import javax.faces.view.ViewScoped
import java.io.Serializable;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
@Named
@ViewScoped
public class SimpleBean implements Serializable
{
private final Logger logger = Logger.getLogger(SimpleBean.class.getName());
@PostConstruct
private void init()
{
logger.log(Level.SEVERE, "{0}.init()", this);
}
private String name;
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String action()
{
logger.log(Level.SEVERE, "{0}.action()", this);
logger.log(Level.SEVERE,"====================");
logger.log(Level.SEVERE, "name: {0}", getName());
logger.log(Level.SEVERE,"====================");
return "submit";
}
}
因此,我有一个带有表单的简单index.xhtml页面
<h:form>
<h:inputText value="#{simpleBean.name}"></h:inputText>
<h:link value="To submit" outcome="submit"/>
<h:commandButton value="Welcome Me" action="#{simpleBean.action()}"/>
</h:form>
我们可以看到SimpleBean有两个不同的实例。然后我提交第一个选项卡的表单
Severe: solvo.ee.beans.SimpleBean@2adafd68.action()
Severe: ====================
Severe: name: First tab
Severe: ====================
Finest: Handling PreDestroyViewMapEvent
Finest: Destroying @viewscoped beans from view map: {simpleBean=solvo.ee.beans.SimpleBean@2adafd68}
Finest: Handling PreDestroyViewMapEvent
Finest: Destroying @viewscoped beans from view map: {}
如果我尝试提交第二个选项卡的表单,则提交存储的早期SimpleBean实例(solvo.ee.beans)。SimpleBean@49a86248)将不使用,取而代之的是ViewScopeContextManager将创建SimpleBean类的新实例,如日志中所示:
Severe: solvo.ee.beans.SimpleBean@4797f115.init()
Severe: solvo.ee.beans.SimpleBean@4797f115.action()
Severe: ====================
Severe: name: Second tab
Severe: ====================
Finest: Handling PreDestroyViewMapEvent
Finest: Destroying @viewscoped beans from view map: {simpleBean=solvo.ee.beans.SimpleBean@4797f115}
Finest: Handling PreDestroyViewMapEvent
Finest: Destroying @viewscoped beans from view map: {}
我已经检查了com.sun.faces.application.view.ViewScopeContextManager.copyViewScopeContextsFromSession方法的代码,据我所知,这种行为是正常的。
但是,如果我在bean中存储请求参数或其他重要数据,我将丢失它,因为在提交第一个表单后实例将丢失
有没有一种解决方案可以让bean主要与第二个选项卡相关联(在我的示例solvo.ee.beans中)。SimpleBean@49a86248)?这似乎是Mojarra的一个bug,将在2.3.10中修复,根据本文:
从同一个线程来看,Payara似乎已经在不等待2.3.10版本的情况下应用了补丁。升级到修补过的Payara是否为您解决了问题?您是否能够找到解决此问题的方法?我有完全相同的一个:可能重复的
Severe: solvo.ee.beans.SimpleBean@4797f115.init()
Severe: solvo.ee.beans.SimpleBean@4797f115.action()
Severe: ====================
Severe: name: Second tab
Severe: ====================
Finest: Handling PreDestroyViewMapEvent
Finest: Destroying @viewscoped beans from view map: {simpleBean=solvo.ee.beans.SimpleBean@4797f115}
Finest: Handling PreDestroyViewMapEvent
Finest: Destroying @viewscoped beans from view map: {}