Troubleshooting java.lang.IllegalStateException: Context is already active - jsf

In a JSF 2.1 Project I am using Primefaces 5.2.
It is deployed on a Glasfish 3.1.2.2
Problem:
I´ve got the problem, that I am getting a
java.lang.IllegalStateException: Context is already active
sometimes, when I am doing a refresh page or a page redirect.
I do know, that sometimes is not a very good definition of software behaviour, but i can not really reproduce the error, it seems to appear random, to me.
Question:
Hence, I have not really found too much on the web about the cause of that kind of Exception im wondering what circumstances can produce it?
Full Trace:
[#|2015-11-10T12:51:30.246+0100|WARNING|oracle-glassfish3.1.2|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=141;_ThreadName=Thread-8;|StandardWrapperValve[Faces Servlet]: PWC1406: Servlet.service() for servlet Faces Servlet threw exception
java.lang.IllegalStateException: Context is already active
at org.jboss.weld.context.AbstractConversationContext.activate(AbstractConversationContext.java:227)
at org.jboss.weld.jsf.WeldPhaseListener.activateConversations(WeldPhaseListener.java:108)
at org.jboss.weld.jsf.WeldPhaseListener.beforePhase(WeldPhaseListener.java:85)
at com.sun.faces.lifecycle.Phase.handleBeforePhase(Phase.java:228)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:99)
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:100)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.core.StandardHostValve.__invoke(StandardHostValve.java:161)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:745)
|#]

Solving the concrete problem you're facing is difficult based on the limited information available, but I believe I can answer your actual stated question.
The exception you're getting is triggered when your application attempts to activate a context before deactivating the previously activated one. Based on your stacktrace it seems you are activating a new conversation before the previous one. Depending on your implementation it could simply be a timing issue but it's difficult to say for sure without reviewing the codebase.
To clarify why activating a second context is a problem, it's against the CDI spec. You can have zero or one active contexts per scope per thread, any more and you end up with ambiguity between contextual instances.
As a non-technical analogue, a scope is a shelf with boxes (contexts) on it. You can only have box open (active) at any time, otherwise your little brother (CDI container / Weld) won't know which box you meant when you said to get the action figure (contextual instance) from the open box on the top shelf (Or #Inject MyBeanInterface bean; where the bean has an assigned scope).

Related

Liferay portlet won't be shown

I already postet my Question in the Liferayforum, but without any Answer.
https://www.liferay.com/de/community/forums/-/message_boards/message/55035046
I'm developing some Portlets with JSF Primefaces.
But sometimes the Portlets wont be shown and there is only empty space.
This happens just sometimes, without any reproducible reasons.
Any Idea for this Issue?
Following Log:
14:41:41,416 ERROR [RuntimePageImpl-9][render_portlet_jsp:132] null
java.lang.NullPointerException
at org.primefaces.component.chart.renderer.PieRenderer.encodeData(PieRenderer.java:34)
at org.primefaces.component.chart.renderer.BasePlotRenderer.render(BasePlotRenderer.java:29)
at org.primefaces.component.chart.ChartRenderer.encodeScript(ChartRenderer.java:98)
at org.primefaces.component.chart.ChartRenderer.encodeEnd(ChartRenderer.java:67)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:881)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1786)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:439)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:124)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:286)
at com.liferay.faces.bridge.application.ViewHandlerCompatImpl.renderView(ViewHandlerCompatImpl.java:52)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at com.liferay.faces.bridge.BridgePhaseRenderImpl.execute(BridgePhaseRenderImpl.java:227)
at com.liferay.faces.bridge.BridgePhaseRenderImpl.execute(BridgePhaseRenderImpl.java:85)
at com.liferay.faces.bridge.BridgeImpl.doFacesRequest(BridgeImpl.java:112)
at javax.portlet.faces.GenericFacesPortlet.doView(GenericFacesPortlet.java:255)
at javax.portlet.GenericPortlet.doDispatch(GenericPortlet.java:328)
For Those Reasons, are there any Error-Handling methods?
If my Portlet will throw an exception, I just wan't to show a self-defined Error-Message or something.
Thanks
Actually you have to find the Source of the NPE. If you have located where the NPE is originating you could wrap a try/catch around and use the
SessionErrors.add(actionRequest, "error-key");
method to add your error. For displaying it you would add this to your jsp:
<liferay-ui:error key="error-key" message="this-is-error-message-1" />

java.lang.ClassCastException: javax.faces.component.StateHolderSaver cannot be cast to [Ljava.lang.Object;

I am displaying a list of items with links in my xhtml page. When I click my "back to previous page" button from that link, I basically reset the flags in my bean to indicate to the xhtml which page to display, and reload the list of links from my database.
When I click the same link (or any other link for that matter) in this new page, I get this error:
javax.portlet.faces.BridgeException: javax.portlet.faces.BridgeException: javax.faces.FacesException:
Unexpected error restoring state for component with id A8351:j_idt7:j_idt10:j_idt59.
Cause: java.lang.ClassCastException: javax.faces.component.StateHolderSaver cannot be cast to [Ljava.lang.Object;.
at com.liferay.faces.bridge.BridgePhaseActionImpl.execute(BridgePhaseActionImpl.java:105)
at com.liferay.faces.bridge.BridgeImpl.doFacesRequest(BridgeImpl.java:81)
at javax.portlet.faces.GenericFacesPortlet.processAction(GenericFacesPortlet.java:152)
at com.ncs.portalcity.lfe.faces.bridge.FacesPortlet.processAction(FacesPortlet.java:47)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:70)
at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:48)
at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
...
...
Caused by: javax.faces.FacesException: Unexpected error restoring state for component
with id A8351:j_idt7:j_idt10:j_idt59. Cause: java.lang.ClassCastException: javax.faces.component.StateHolderSaver cannot be cast to [Ljava.lang.Object;.
at com.sun.faces.application.view.StateManagementStrategyImpl$2.visit(StateManagementStrategyImpl.java:284)
at com.sun.faces.component.visit.FullVisitContext.invokeVisitCallback(FullVisitContext.java:151)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1589)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600)
at javax.faces.component.UIForm.visitTree(UIForm.java:344)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600)
at com.sun.faces.application.view.StateManagementStrategyImpl.restoreView(StateManagementStrategyImpl.java:263)
at com.sun.faces.application.StateManagerImpl.restoreView(StateManagerImpl.java:188)
at com.sun.faces.application.view.ViewHandlingStrategy.restoreView(ViewHandlingStrategy.java:123)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.restoreView(FaceletViewHandlingStrategy.java:452)
at com.sun.faces.application.view.MultiViewHandler.restoreView(MultiViewHandler.java:148)
at javax.faces.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:303)
at com.liferay.faces.bridge.application.ViewHandlerImpl.restoreView(ViewHandlerImpl.java:88)
at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:192)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at com.liferay.faces.bridge.lifecycle.LifecycleWrapper.execute(LifecycleWrapper.java:35)
at com.liferay.faces.bridge.BridgePhaseActionImpl.execute(BridgePhaseActionImpl.java:77)
... 142 more
Caused by: java.lang.ClassCastException: javax.faces.component.StateHolderSaver cannot be cast to [Ljava.lang.Object;
at javax.faces.component.behavior.AjaxBehavior.restoreState(AjaxBehavior.java:459)
at javax.faces.component.UIComponentBase.restoreBehaviors(UIComponentBase.java:2184)
at javax.faces.component.UIComponentBase.restoreBehaviorsState(UIComponentBase.java:2151)
at javax.faces.component.UIComponentBase.restoreState(UIComponentBase.java:1571)
at com.sun.faces.application.view.StateManagementStrategyImpl$2.visit(StateManagementStrategyImpl.java:276)
... 162 more
If I refresh the page and try again, there are no issues. Does anyone have any idea what I'm doing wrong?
---- Edit ----
Just in case anyone else using liferay has this problem, I just added these lines in my pom.xml and it's ok now :) Thanks so much BaluC!
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1.21</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.1.21</version>
<scope>compile</scope>
</dependency>
This is a known Mojarra issue and already reported as issue 2041 which is fixed in Mojarra 2.1.12.
So, just upgrading your JSF libraries to at least Mojarra 2.1.12 should do. It's currently already at 2.1.26, with many more fixes related to state management and likes as compared to 2.1.12.

javax.servlet.ServletException: Can't find bundle for base name messages, locale es

Sometimes I get the error:
"javax.servlet.ServletException: Can not find bundle for messages based name, locale is"
I have a JSF application with primefaces where bundle messages, almost always working correctly except for one case in a xhtml, clicking a button one that saves data in a , sometimes works and sometimes not, depending on what images to include or not the object p: editor. When it fails with the following error, as if not to find the messages:
Estado HTTP 500 - Can't find bundle for base name messages, locale es
type Informe de Excepción
mensaje Can't find bundle for base name messages, locale es
descripción El servidor encontró un error interno que hizo que no pudiera rellenar este requerimiento.
excepción
javax.servlet.ServletException: Can't find bundle for base name messages, locale es
javax.faces.webapp.FacesServlet.service(FacesServlet.java:321)
uned.lsi.security.SecurityFilter.doFilter(SecurityFilter.java:62)
causa raíz
java.util.MissingResourceException: Can't find bundle for base name messages, locale es
java.util.ResourceBundle.throwMissingResourceException(Unknown Source)
java.util.ResourceBundle.getBundleImpl(Unknown Source)
java.util.ResourceBundle.getBundle(Unknown Source)
javax.faces.validator.MessageFactory.getMessage(MessageFactory.java:155)
javax.faces.validator.MessageFactory.getMessage(MessageFactory.java:245)
javax.faces.validator.LengthValidator.validate(LengthValidator.java:228)
javax.faces.component.UIInput.validateValue(UIInput.java:1142)
javax.faces.component.UIInput.validate(UIInput.java:960)
javax.faces.component.UIInput.executeValidate(UIInput.java:1204)
javax.faces.component.UIInput.processValidators(UIInput.java:693)
javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
javax.faces.component.UIForm.processValidators(UIForm.java:240)
javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
org.primefaces.component.panel.Panel.processValidators(Panel.java:293)
javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1159)
com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:72)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:308)
uned.lsi.security.SecurityFilter.doFilter(SecurityFilter.java:62)
Although it may be the configuration of bounle posts, because it works almost always leave here as I have:
faces-config
<application>
<message-bundle> messages </ message-bundle>
<locale-config>
<default-locale> is </ default-locale>
</ Locale-config>
<resource-bundle>
<base-name> MessageResources </ base-name>
<var> msg </ var>
</ Resource-bundle>
</Application>
xhtml error:
<f:loadBundle basename="MessageResources" var="msg"/>
MessageResources.properties file, the src directory.
Thanks in advance, in case someone ever happened something similar.
The error you got is referring to the <message-bundle> in faces-config.xml, not to the <resource-bundle> nor the <f:loadBundle> which you seemed to expect.
First of all, please carefully go through the following answer to learn about the difference: Internationalization in JSF, when to use message-bundle and resource-bundle?
So, the message bundle is for JSF's own standard converters/validators such as <f:convertDateTime>, required="true", <f:validateLength>, etc and the resource bundle is for your own i18n text stuff such as headers, paragraphs, labels, tooltips, etc. Please note the involvement of LengthValidator in the stack trace during UIInput#validate() call of ProcessValidationsPhase. This should already have given some hints about the real problem.
Fix/align it accordingly. Perhaps you just need to get rid of <message-bundle> altogether and rely on JSF default conversion/validation messages.

XPage Dojo DateTextBox NotSerializableException

i have a xpage including a dojo DateTextBox. If i save the document, everything works well. But if i reopen the document, i get the following Exception:
Unexpected runtime error
The runtime has encountered an unexpected error.
Error source
Page Name:/OfferAccount.xsp
Exception
java.io.NotSerializableException: lotus.domino.local.DateTime
lotus.domino.local.DateTime
Stack Trace:
com.ibm.xsp.FacesExceptionEx: java.io.NotSerializableException: lotus.domino.local.DateTime
com.ibm.xsp.application.AbstractStateManager.saveSerializedView(AbstractStateManager.java:121)
com.ibm.xsp.application.StateManagerImpl.saveSerializedView(StateManagerImpl.java:152)
com.ibm.xsp.application.ViewHandlerExImpl._saveViewState(ViewHandlerExImpl.java:445)
com.ibm.xsp.application.ViewHandlerExImpl.saveViewState(ViewHandlerExImpl.java:439)
com.ibm.xsp.application.ViewHandlerExImpl._renderView(ViewHandlerExImpl.java:323)
com.ibm.xsp.application.ViewHandlerExImpl.renderView(ViewHandlerExImpl.java:335)
Here is the code of the DateTextBox in my xpage:
<xe:djDateTextBox
id="periodOfInsuranceBeginn" value="#{offerAccount.d_offerPolicyBegin}">
<xe:this.defaultValue><![CDATA[#{javascript:var today:NotesDateTime =
session.createDateTime(#Today());
return I18n.parseDate(today.getDateOnly());}]]></xe:this.defaultValue>
<xp:this.converter>
<xp:convertDateTime type="date" dateStyle="short">
</xp:convertDateTime>
</xp:this.converter>
</xe:djDateTextBox>
This Exception also occurs, if i use an EditBox of type dateTime.
Any ideas?
Thanks Mario
It seems that you use a Notes object (NotesDateTime) in your code. Notes objects are not serializable. Store them as a Java date instead and convert them back to a NotesDateTime object if you acces them.

myFaces Trinidad example not displaying

Hi I have followed the setup guide at:
http://myfaces.apache.org/trinidad/installation.html
When I include the following code in my faces-config.xml file I get an error when I hit a page:
<application>
<default-render-kit-id>org.apache.myfaces.trinidad.core</default-render-kit-id>
</application>
Start of Error:
java.lang.IllegalStateException: No RenderingContext
at org.apache.myfaces.trinidad.render.CoreRenderer.encodeBegin(CoreRenderer.java:390)
at org.apache.myfaces.trinidadinternal.renderkit.htmlBasic.HtmlFormRenderer.encodeBegin(HtmlFormRenderer.java:56)
at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:813)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:928)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:933)
at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
When I remove that piece of code from my faces-config.xml file I can navigate my site as normal, but when I hit a page that has some sample Trinidad code nothing is displayed...just an empty page.
Any ideas on what I'm doing wrong?
I removed the following from my web.xml and its working now, any ideas? Confused :(
<context-param>
<param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
<param-value>com.sun.facelets.FaceletViewHandler</param-value>
</context-param>
Thanks
I've actually discovered an excellent control for Richfaces that will provide the same functionailty. I'm going to go with this instead.
http://livedemo.exadel.com/richfaces-demo/richfaces/extendedDataTable.jsf?c=extendedDataTable&tab=usage
As BalsusC suggested, mixing different ajaxical component libraries might not be such a good idea.
Additionally, I have found the documentation and examples for Trinidad to be quite poor; Particularly in comparasion to Richfaces.
Would I be correct in thinking Trinidad is slowly dying?

Resources