问题描述
我终于可以正常工作了,但并非没有多余的东西。首先,我在web.xml中添加了以下内容(是的,拼写错误):
<context-param>
<param-name>com.sun.faces.enableAgressiveSessionDirtying</param-name>
<param-value>true</param-value>
</context-param>
现在,客户端保存为服务器,部分状态保存仍为false(true根本不起作用)
其次,在实现HttpSessionAttributeListener之后,我发现com.sun.faces.renderkit.ServerSideStateHelper.LogicalViewMap
在会话中保存状态的只会被添加一次,而不会再被删除/添加/替换。因此,尽管在本地会话中对其进行了更新,但这些更改从未复制到另一个jvm。Weblogic文档指出必须在会话属性上调用setAttribute才能使复制正常工作。为了解决这个问题,我创建了一个阶段侦听器,如下所示:
public class ViewPhaseListener implements PhaseListener {
public void afterPhase(PhaseEvent phaseEvent)
{
}
public void beforePhase(PhaseEvent phaseEvent)
{
HttpServletRequest request = ((HttpServletRequest) phaseEvent.getFacesContext().getExternalContext().getRequest());
HttpSession session = request.getSession();
session.setAttribute("com.sun.faces.renderkit.ServerSideStateHelper.LogicalViewMap", session.getAttribute("com.sun.faces.renderkit.ServerSideStateHelper.LogicalViewMap"));
}
public PhaseId getPhaseId()
{
return PhaseId.RENDER_RESPONSE;
//To change body of implemented methods use File | Settings | File Templates.
}
}
这只是在每个请求之后替换属性,并确保它可以复制。另外,我使用以下方法限制了视图中存储的数据:
<context-param>
<param-name>com.sun.faces.numberOfViewsInSession</param-name>
<param-value>3</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.numberOfLogicalViews</param-name>
<param-value>1</param-value>
</context-param>
希望这对遇到相同问题的人有所帮助。
解决方法
在JSF 2.0.9,Weblogic
10.3.4上运行。我们现在在生产环境中运行JSF,但是会话复制遇到了一些问题并进行了故障转移。我们正在为我们的bean使用viewscope,我已经确保它们是可序列化的/瞬态的,并且瞬态变量实际上是无状态的。但是,会话故障转移不起作用。我已经进行了广泛的测试,并设法通过在web.xml中设置以下参数来使其正常工作
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
<param-value>false</param-value>
</context-param>
如果设置STATE_SAVING_METHOD
为,则server
在故障转移时会收到viewexpired异常。如果我设置为client
同PARTIAL_STATE_SAVING
来true
我得到以下错误:
java.lang.IndexOutOfBoundsException: Index: 0,Size: 0
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
at java.util.ArrayList.get(ArrayList.java:322)
at javax.faces.component.AttachedObjectListHolder.restoreState(AttachedObjectListHolder.java:165)
at javax.faces.component.UIComponentBase.restoreState(UIComponentBase.java:1433)
at com.sun.faces.application.view.StateManagementStrategyImpl$1.visit(StateManagementStrategyImpl.java:265)
at com.sun.faces.component.visit.FullVisitContext.invokeVisitCallback(FullVisitContext.java:151)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1507)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1521)
at com.sun.faces.component.visit.VisitUtils.doFullNonIteratingVisit(VisitUtils.java:75)
at com.sun.faces.application.view.StateManagementStrategyImpl.restoreView(StateManagementStrategyImpl.java:282)
at com.sun.faces.application.StateManagerImpl.restoreView(StateManagerImpl.java:181)
at com.sun.faces.application.view.ViewHandlingStrategy.restoreView(ViewHandlingStrategy.java:123)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.restoreView(FaceletViewHandlingStrategy.java:448)
at com.sun.faces.application.view.MultiViewHandler.restoreView(MultiViewHandler.java:148)
at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:187)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:111)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:508)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:301)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:27)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:57)
at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:57)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3730)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3696)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2273)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1490)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
所以我的问题是:
- 是
STATE_SAVING_METHOD
-client
&PARTIAL_STATE_SAVING
-false
我要进行故障转移的唯一方法吗? - 客户/错误组合的成本是多少?此内存/ CPU是否扩展?
- 这是一个错误吗?如果是,那么可以在2.1或2.2中解决吗?
提前致谢。